MythTV  master
channel.cpp
Go to the documentation of this file.
1 // Program Name: channel.cpp
3 // Created : Apr. 8, 2011
4 //
5 // Copyright (c) 2011 Robert McNamara <rmcnamara@mythtv.org>
6 // Copyright (c) 2013 MythTV Developers
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program. If not, see <http://www.gnu.org/licenses/>.
24 //
26 
27 // C++
28 #include <cmath>
29 
30 // Qt
31 #include <QList>
32 
33 // MythTV
34 #include "libmythbase/compat.h"
36 #include "libmythbase/mythdate.h"
37 #include "libmythbase/mythdbcon.h"
38 #include "libmythbase/mythdirs.h"
40 #include "libmythtv/cardutil.h"
41 #include "libmythtv/channelutil.h"
42 #include "libmythtv/sourceutil.h"
43 
44 // MythBackend
45 #include "channel.h"
46 #include "serviceUtil.h"
47 
49 //
51 
53  uint nChannelGroupID,
54  uint nStartIndex,
55  uint nCount,
56  bool bOnlyVisible,
57  bool bDetails,
58  bool bOrderByName,
59  bool bGroupByCallsign,
60  bool bOnlyTunable )
61 {
62  ChannelInfoList chanList;
63 
64  uint nTotalAvailable = 0;
65 
66  chanList = ChannelUtil::LoadChannels( 0, 0, nTotalAvailable, bOnlyVisible,
69  nSourceID, nChannelGroupID, false, "",
70  "", bOnlyTunable);
71 
72  // ----------------------------------------------------------------------
73  // Build Response
74  // ----------------------------------------------------------------------
75 
76  auto *pChannelInfos = new DTC::ChannelInfoList();
77 
78  nStartIndex = (nStartIndex > 0) ? std::min( nStartIndex, nTotalAvailable ) : 0;
79  nCount = (nCount > 0) ? std::min(nCount, (nTotalAvailable - nStartIndex)) :
80  (nTotalAvailable - nStartIndex);
81 
82  ChannelInfoList::iterator chanIt;
83  auto chanItBegin = chanList.begin() + nStartIndex;
84  auto chanItEnd = chanItBegin + nCount;
85 
86  for( chanIt = chanItBegin; chanIt < chanItEnd; ++chanIt )
87  {
88  DTC::ChannelInfo *pChannelInfo = pChannelInfos->AddNewChannelInfo();
89 
90  ChannelInfo channelInfo = (*chanIt);
91 
92  if (!FillChannelInfo(pChannelInfo, channelInfo, bDetails))
93  {
94  delete pChannelInfo;
95  delete pChannelInfos;
96  throw( QString("Channel ID appears invalid."));
97  }
98  }
99 
100  int nCurPage = 0;
101  int nTotalPages = 0;
102  if (nCount == 0)
103  nTotalPages = 1;
104  else
105  nTotalPages = (int)std::ceil((float)nTotalAvailable / nCount);
106 
107  if (nTotalPages == 1)
108  nCurPage = 1;
109  else
110  {
111  nCurPage = (int)std::ceil((float)nStartIndex / nCount) + 1;
112  }
113 
114  pChannelInfos->setStartIndex ( nStartIndex );
115  pChannelInfos->setCount ( nCount );
116  pChannelInfos->setCurrentPage ( nCurPage );
117  pChannelInfos->setTotalPages ( nTotalPages );
118  pChannelInfos->setTotalAvailable( nTotalAvailable );
119  pChannelInfos->setAsOf ( MythDate::current() );
120  pChannelInfos->setVersion ( MYTH_BINARY_VERSION );
121  pChannelInfos->setProtoVer ( MYTH_PROTO_VERSION );
122 
123  return pChannelInfos;
124 }
125 
127 //
129 
131 {
132  if (nChanID == 0)
133  throw( QString("Channel ID appears invalid."));
134 
135  auto *pChannelInfo = new DTC::ChannelInfo();
136 
137  if (!FillChannelInfo(pChannelInfo, nChanID, true))
138  {
139  // throw causes a crash on linux and we can't know in advance
140  // that a channel id from an old recording rule is invalid
141  //throw( QString("Channel ID appears invalid."));
142  }
143 
144  return pChannelInfo;
145 }
146 
148  uint SourceID,
149  uint ChannelID,
150  const QString &CallSign,
151  const QString &ChannelName,
152  const QString &ChannelNumber,
153  uint ServiceID,
154  uint ATSCMajorChannel,
155  uint ATSCMinorChannel,
156  bool UseEIT,
157  bool Visible,
158  const QString &ExtendedVisible,
159  const QString &FrequencyID,
160  const QString &Icon,
161  const QString &Format,
162  const QString &XMLTVID,
163  const QString &DefaultAuthority,
164  uint ServiceType )
165 {
166  if (!HAS_PARAM("channelid"))
167  throw QString("ChannelId is required");
168 
169  if (m_parsedParams.size() < 2 )
170  throw QString("Nothing to update");
171 
172  ChannelInfo channel;
173  if (!channel.Load(ChannelID))
174  throw QString("ChannelId %1 doesn't exist");
175 
176  if (HAS_PARAM("mplexid"))
177  channel.m_mplexId = MplexID;
178  if (HAS_PARAM("sourceid"))
179  channel.m_sourceId = SourceID;
180  if (HAS_PARAM("callsign"))
181  channel.m_callSign = CallSign;
182  if (HAS_PARAM("channelname"))
183  channel.m_name = ChannelName;
184  if (HAS_PARAM("channelnumber"))
185  channel.m_chanNum = ChannelNumber;
186  if (HAS_PARAM("serviceid"))
187  channel.m_serviceId = ServiceID;
188  if (HAS_PARAM("atscmajorchannel"))
189  channel.m_atscMajorChan = ATSCMajorChannel;
190  if (HAS_PARAM("atscminorchannel"))
191  channel.m_atscMinorChan = ATSCMinorChannel;
192  if (HAS_PARAM("useeit"))
193  channel.m_useOnAirGuide = UseEIT;
194 
195  if (HAS_PARAM("extendedvisible"))
196  {
197 #ifndef _WIN32 // TODO Does not compile on Windows
198  channel.m_visible = channelVisibleTypeFromString(ExtendedVisible);
199 #else
200  Q_UNUSED(ExtendedVisible);
201 #endif
202  }
203  else if (HAS_PARAM("visible"))
204  {
205  if (channel.m_visible == kChannelVisible ||
206  channel.m_visible == kChannelNotVisible)
207  {
208  channel.m_visible =
210  }
211  else if ((channel.m_visible == kChannelAlwaysVisible && !Visible) ||
212  (channel.m_visible == kChannelNeverVisible && Visible))
213  {
214  throw QString("Can't override Always/NeverVisible");
215  }
216  }
217  if (HAS_PARAM("frequencyid"))
218  channel.m_freqId = FrequencyID;
219  if (HAS_PARAM("icon"))
220  channel.m_icon = Icon;
221  if (HAS_PARAM("format"))
222  channel.m_tvFormat = Format;
223  if (HAS_PARAM("xmltvid"))
224  channel.m_xmltvId = XMLTVID;
225  if (HAS_PARAM("defaultauthority"))
226  channel.m_defaultAuthority = DefaultAuthority;
227  if (HAS_PARAM("servicetype"))
228  channel.m_serviceType = ServiceType;
229 
230  bool bResult = ChannelUtil::UpdateChannel(
231  channel.m_mplexId, channel.m_sourceId, channel.m_chanId,
232  channel.m_callSign, channel.m_name, channel.m_chanNum,
233  channel.m_serviceId, channel.m_atscMajorChan,
234  channel.m_atscMinorChan, channel.m_useOnAirGuide,
235  channel.m_visible, channel.m_freqId,
236  channel.m_icon, channel.m_tvFormat, channel.m_xmltvId,
237  channel.m_defaultAuthority, channel.m_serviceType );
238 
239  return bResult;
240 }
241 
243  uint SourceID,
244  uint ChannelID,
245  const QString &CallSign,
246  const QString &ChannelName,
247  const QString &ChannelNumber,
248  uint ServiceID,
249  uint ATSCMajorChannel,
250  uint ATSCMinorChannel,
251  bool UseEIT,
252  bool Visible,
253  const QString &ExtendedVisible,
254  const QString &FrequencyID,
255  const QString &Icon,
256  const QString &Format,
257  const QString &XMLTVID,
258  const QString &DefaultAuthority,
259  uint ServiceType )
260 {
261  ChannelVisibleType chan_visible = kChannelVisible;
262 
263  #ifdef _WIN32 // TODO Needs fixing for Windows
264  Q_UNUSED(ExtendedVisible);
265  chan_visible = (Visible ? kChannelVisible : kChannelNotVisible);
266  #else
267  if (HAS_PARAM("extendedvisible"))
268  chan_visible = channelVisibleTypeFromString(ExtendedVisible);
269  else if (HAS_PARAM("visible"))
270  chan_visible = (Visible ? kChannelVisible : kChannelNotVisible);
271  #endif
272 
273 
274  bool bResult = ChannelUtil::CreateChannel( MplexID, SourceID, ChannelID,
275  CallSign, ChannelName, ChannelNumber,
276  ServiceID, ATSCMajorChannel, ATSCMinorChannel,
277  UseEIT, chan_visible, FrequencyID,
278  Icon, Format, XMLTVID, DefaultAuthority,
279  ServiceType );
280 
281  return bResult;
282 }
283 
284 bool Channel::RemoveDBChannel( uint nChannelID )
285 {
286  bool bResult = ChannelUtil::DeleteChannel( nChannelID );
287 
288  return bResult;
289 }
290 
292 //
294 
296 {
297  MSqlQuery query(MSqlQuery::InitCon());
298 
299  if (!query.isConnected())
300  throw( QString("Database not open while trying to list "
301  "Video Sources."));
302 
303  query.prepare("SELECT sourceid, name, xmltvgrabber, userid, "
304  "freqtable, lineupid, password, useeit, configpath, "
305  "dvb_nit_id, bouquet_id, region_id, scanfrequency, "
306  "lcnoffset FROM videosource "
307  "ORDER BY sourceid" );
308 
309  if (!query.exec())
310  {
311  MythDB::DBError("MythAPI::GetVideoSourceList()", query);
312 
313  throw( QString( "Database Error executing query." ));
314  }
315 
316  // ----------------------------------------------------------------------
317  // return the results of the query
318  // ----------------------------------------------------------------------
319 
320  auto* pList = new DTC::VideoSourceList();
321 
322  while (query.next())
323  {
324 
325  DTC::VideoSource *pVideoSource = pList->AddNewVideoSource();
326 
327  pVideoSource->setId ( query.value(0).toInt() );
328  pVideoSource->setSourceName ( query.value(1).toString() );
329  pVideoSource->setGrabber ( query.value(2).toString() );
330  pVideoSource->setUserId ( query.value(3).toString() );
331  pVideoSource->setFreqTable ( query.value(4).toString() );
332  pVideoSource->setLineupId ( query.value(5).toString() );
333  pVideoSource->setPassword ( query.value(6).toString() );
334  pVideoSource->setUseEIT ( query.value(7).toBool() );
335  pVideoSource->setConfigPath ( query.value(8).toString() );
336  pVideoSource->setNITId ( query.value(9).toInt() );
337  pVideoSource->setBouquetId ( query.value(10).toUInt() );
338  pVideoSource->setRegionId ( query.value(11).toUInt() );
339  pVideoSource->setScanFrequency ( query.value(12).toUInt() );
340  pVideoSource->setLCNOffset ( query.value(13).toUInt() );
341  }
342 
343  pList->setAsOf ( MythDate::current() );
344  pList->setVersion ( MYTH_BINARY_VERSION );
345  pList->setProtoVer ( MYTH_PROTO_VERSION );
346 
347  return pList;
348 }
349 
351 //
353 
355 {
356  MSqlQuery query(MSqlQuery::InitCon());
357 
358  if (!query.isConnected())
359  throw( QString("Database not open while trying to list "
360  "Video Sources."));
361 
362  query.prepare("SELECT name, xmltvgrabber, userid, "
363  "freqtable, lineupid, password, useeit, configpath, "
364  "dvb_nit_id, bouquet_id, region_id, scanfrequency, "
365  "lcnoffset "
366  "FROM videosource WHERE sourceid = :SOURCEID "
367  "ORDER BY sourceid" );
368  query.bindValue(":SOURCEID", nSourceID);
369 
370  if (!query.exec())
371  {
372  MythDB::DBError("MythAPI::GetVideoSource()", query);
373 
374  throw( QString( "Database Error executing query." ));
375  }
376 
377  // ----------------------------------------------------------------------
378  // return the results of the query
379  // ----------------------------------------------------------------------
380 
381  auto *pVideoSource = new DTC::VideoSource();
382 
383  if (query.next())
384  {
385  pVideoSource->setId ( nSourceID );
386  pVideoSource->setSourceName ( query.value(0).toString() );
387  pVideoSource->setGrabber ( query.value(1).toString() );
388  pVideoSource->setUserId ( query.value(2).toString() );
389  pVideoSource->setFreqTable ( query.value(3).toString() );
390  pVideoSource->setLineupId ( query.value(4).toString() );
391  pVideoSource->setPassword ( query.value(5).toString() );
392  pVideoSource->setUseEIT ( query.value(6).toBool() );
393  pVideoSource->setConfigPath ( query.value(7).toString() );
394  pVideoSource->setNITId ( query.value(8).toInt() );
395  pVideoSource->setBouquetId ( query.value(9).toUInt() );
396  pVideoSource->setRegionId ( query.value(10).toUInt() );
397  pVideoSource->setScanFrequency ( query.value(11).toUInt() );
398  pVideoSource->setLCNOffset ( query.value(12).toUInt() );
399  }
400 
401  return pVideoSource;
402 }
403 
405 //
407 
409  const QString &sSourceName,
410  const QString &sGrabber,
411  const QString &sUserId,
412  const QString &sFreqTable,
413  const QString &sLineupId,
414  const QString &sPassword,
415  bool bUseEIT,
416  const QString &sConfigPath,
417  int nNITId,
418  uint nBouquetId,
419  uint nRegionId,
420  uint nScanFrequency,
421  uint nLCNOffset )
422 {
423 
424  if (!HAS_PARAM("sourceid"))
425  {
426  LOG(VB_GENERAL, LOG_ERR, "SourceId is required");
427  return false;
428  }
429 
430  if (!SourceUtil::IsSourceIDValid(nSourceId))
431  {
432  LOG(VB_GENERAL, LOG_ERR, QString("SourceId %1 doesn't exist")
433  .arg(nSourceId));
434  return false;
435  }
436 
437  if (m_parsedParams.size() < 2 )
438  {
439  LOG(VB_GENERAL, LOG_ERR, QString("SourceId=%1 was the only parameter")
440  .arg(nSourceId));
441  return false;
442  }
443 
444  MSqlBindings bindings;
445  MSqlBindings::const_iterator it;
446  QString settings;
447 
448  if ( HAS_PARAM("sourcename") )
449  ADD_SQL(settings, bindings, "name", "SourceName", sSourceName);
450 
451  if ( HAS_PARAM("grabber") )
452  ADD_SQL(settings, bindings, "xmltvgrabber", "Grabber", sGrabber);
453 
454  if ( HAS_PARAM("userid") )
455  ADD_SQL(settings, bindings, "userid", "UserId", sUserId);
456 
457  if ( HAS_PARAM("freqtable") )
458  ADD_SQL(settings, bindings, "freqtable", "FreqTable", sFreqTable);
459 
460  if ( HAS_PARAM("lineupid") )
461  ADD_SQL(settings, bindings, "lineupid", "LineupId", sLineupId);
462 
463  if ( HAS_PARAM("password") )
464  ADD_SQL(settings, bindings, "password", "Password", sPassword);
465 
466  if ( HAS_PARAM("useeit") )
467  ADD_SQL(settings, bindings, "useeit", "UseEIT", bUseEIT);
468 
469  if (HAS_PARAM("configpath"))
470  {
471  if (sConfigPath.isEmpty())
472  settings += "configpath=NULL, "; // mythfilldatabase grabber requirement
473  else
474  ADD_SQL(settings, bindings, "configpath", "ConfigPath", sConfigPath);
475  }
476 
477  if ( HAS_PARAM("nitid") )
478  ADD_SQL(settings, bindings, "dvb_nit_id", "NITId", nNITId);
479 
480  if ( HAS_PARAM("bouquetid") )
481  ADD_SQL(settings, bindings, "bouquet_id", "BouquetId", nBouquetId);
482 
483  if ( HAS_PARAM("regionid") )
484  ADD_SQL(settings, bindings, "region_id", "RegionId", nRegionId);
485 
486  if ( HAS_PARAM("scanfrequency") )
487  ADD_SQL(settings, bindings, "scanfrequency", "ScanFrequency", nScanFrequency);
488 
489  if ( HAS_PARAM("lcnoffset") )
490  ADD_SQL(settings, bindings, "lcnoffset", "LCNOffset", nLCNOffset);
491 
492  if ( settings.isEmpty() )
493  {
494  LOG(VB_GENERAL, LOG_ERR, "No valid parameters were passed");
495  return false;
496  }
497 
498  settings.chop(2);
499 
500  MSqlQuery query(MSqlQuery::InitCon());
501 
502  query.prepare(QString("UPDATE videosource SET %1 WHERE sourceid=:SOURCEID")
503  .arg(settings));
504  bindings[":SOURCEID"] = nSourceId;
505 
506  for (it = bindings.cbegin(); it != bindings.cend(); ++it)
507  query.bindValue(it.key(), it.value());
508 
509  if (!query.exec())
510  {
511  MythDB::DBError("MythAPI::UpdateVideoSource()", query);
512 
513  throw( QString( "Database Error executing query." ));
514  }
515 
516  return true;
517 }
518 
520 //
522 
523 int Channel::AddVideoSource( const QString &sSourceName,
524  const QString &sGrabber,
525  const QString &sUserId,
526  const QString &sFreqTable,
527  const QString &sLineupId,
528  const QString &sPassword,
529  bool bUseEIT,
530  const QString &sConfigPath,
531  int nNITId,
532  uint nBouquetId,
533  uint nRegionId,
534  uint nScanFrequency,
535  uint nLCNOffset )
536 {
537  int nResult = SourceUtil::CreateSource(sSourceName, sGrabber, sUserId, sFreqTable,
538  sLineupId, sPassword, bUseEIT, sConfigPath,
539  nNITId, nBouquetId, nRegionId, nScanFrequency,
540  nLCNOffset);
541 
542  return nResult;
543 }
544 
546 //
548 
550 {
551  bool bResult = SourceUtil::DeleteSource( nSourceID );
552 
553  return bResult;
554 }
555 
557 //
559 
560 DTC::LineupList* Channel::GetDDLineupList( const QString &/*sSource*/,
561  const QString &/*sUserId*/,
562  const QString &/*sPassword*/ )
563 {
564  auto *pLineups = new DTC::LineupList();
565  return pLineups;
566 }
567 
569 //
571 
573  const uint nCardId,
574  bool bWaitForFinish )
575 {
576  if ( nSourceId < 1 || nCardId < 1)
577  throw( QString("A source ID and card ID are both required."));
578 
579  int nResult = 0;
580 
581  QString cardtype = CardUtil::GetRawInputType(nCardId);
582 
583  if (!CardUtil::IsUnscanable(cardtype) &&
584  !CardUtil::IsEncoder(cardtype))
585  {
586  throw( QString("This device is incompatible with channel fetching.") );
587  }
588 
589  SourceUtil::UpdateChannelsFromListings(nSourceId, cardtype, bWaitForFinish);
590 
591  if (bWaitForFinish)
592  nResult = SourceUtil::GetChannelCount(nSourceId);
593 
594  return nResult;
595 }
596 
598 //
600 
602  uint nStartIndex,
603  uint nCount )
604 {
605  MSqlQuery query(MSqlQuery::InitCon());
606 
607  if (!query.isConnected())
608  throw( QString("Database not open while trying to list "
609  "Video Sources."));
610 
611  query.prepare("SELECT mplexid, sourceid, transportid, networkid, "
612  "frequency, inversion, symbolrate, fec, polarity, "
613  "modulation, bandwidth, lp_code_rate, transmission_mode, "
614  "guard_interval, visible, constellation, hierarchy, hp_code_rate, "
615  "mod_sys, rolloff, sistandard, serviceversion, updatetimestamp, "
616  "default_authority FROM dtv_multiplex WHERE sourceid = :SOURCEID "
617  "ORDER BY mplexid" );
618  query.bindValue(":SOURCEID", nSourceID);
619 
620  if (!query.exec())
621  {
622  MythDB::DBError("MythAPI::GetVideoMultiplexList()", query);
623 
624  throw( QString( "Database Error executing query." ));
625  }
626 
627  uint muxCount = (uint)query.size();
628 
629  // ----------------------------------------------------------------------
630  // Build Response
631  // ----------------------------------------------------------------------
632 
633  auto *pVideoMultiplexes = new DTC::VideoMultiplexList();
634 
635  nStartIndex = (nStartIndex > 0) ? std::min( nStartIndex, muxCount ) : 0;
636  nCount = (nCount > 0) ? std::min( nCount, muxCount ) : muxCount;
637  int nEndIndex = std::min((nStartIndex + nCount), muxCount );
638 
639  for( int n = nStartIndex; n < nEndIndex; n++)
640  {
641  if (query.seek(n))
642  {
643  DTC::VideoMultiplex *pVideoMultiplex = pVideoMultiplexes->AddNewVideoMultiplex();
644 
645  pVideoMultiplex->setMplexId( query.value(0).toInt() );
646  pVideoMultiplex->setSourceId( query.value(1).toInt() );
647  pVideoMultiplex->setTransportId( query.value(2).toInt() );
648  pVideoMultiplex->setNetworkId( query.value(3).toInt() );
649  pVideoMultiplex->setFrequency( query.value(4).toLongLong() );
650  pVideoMultiplex->setInversion( query.value(5).toString() );
651  pVideoMultiplex->setSymbolRate( query.value(6).toLongLong() );
652  pVideoMultiplex->setFEC( query.value(7).toString() );
653  pVideoMultiplex->setPolarity( query.value(8).toString() );
654  pVideoMultiplex->setModulation( query.value(9).toString() );
655  pVideoMultiplex->setBandwidth( query.value(10).toString() );
656  pVideoMultiplex->setLPCodeRate( query.value(11).toString() );
657  pVideoMultiplex->setTransmissionMode( query.value(12).toString() );
658  pVideoMultiplex->setGuardInterval( query.value(13).toString() );
659  pVideoMultiplex->setVisible( query.value(14).toBool() );
660  pVideoMultiplex->setConstellation( query.value(15).toString() );
661  pVideoMultiplex->setHierarchy( query.value(16).toString() );
662  pVideoMultiplex->setHPCodeRate( query.value(17).toString() );
663  pVideoMultiplex->setModulationSystem( query.value(18).toString() );
664  pVideoMultiplex->setRollOff( query.value(19).toString() );
665  pVideoMultiplex->setSIStandard( query.value(20).toString() );
666  pVideoMultiplex->setServiceVersion( query.value(21).toInt() );
667  pVideoMultiplex->setUpdateTimeStamp(
668  MythDate::as_utc(query.value(22).toDateTime()));
669  pVideoMultiplex->setDefaultAuthority( query.value(23).toString() );
670  }
671  }
672 
673  int curPage = 0;
674  int totalPages = 0;
675  if (nCount == 0)
676  totalPages = 1;
677  else
678  totalPages = (int)std::ceil((float)muxCount / nCount);
679 
680  if (totalPages == 1)
681  curPage = 1;
682  else
683  {
684  curPage = (int)std::ceil((float)nStartIndex / nCount) + 1;
685  }
686 
687  pVideoMultiplexes->setStartIndex ( nStartIndex );
688  pVideoMultiplexes->setCount ( nCount );
689  pVideoMultiplexes->setCurrentPage ( curPage );
690  pVideoMultiplexes->setTotalPages ( totalPages );
691  pVideoMultiplexes->setTotalAvailable( muxCount );
692  pVideoMultiplexes->setAsOf ( MythDate::current() );
693  pVideoMultiplexes->setVersion ( MYTH_BINARY_VERSION );
694  pVideoMultiplexes->setProtoVer ( MYTH_PROTO_VERSION );
695 
696  return pVideoMultiplexes;
697 }
698 
700 {
701  MSqlQuery query(MSqlQuery::InitCon());
702 
703  if (!query.isConnected())
704  throw( QString("Database not open while trying to list "
705  "Video Multiplex."));
706 
707  query.prepare("SELECT sourceid, transportid, networkid, "
708  "frequency, inversion, symbolrate, fec, polarity, "
709  "modulation, bandwidth, lp_code_rate, transmission_mode, "
710  "guard_interval, visible, constellation, hierarchy, hp_code_rate, "
711  "mod_sys, rolloff, sistandard, serviceversion, updatetimestamp, "
712  "default_authority FROM dtv_multiplex WHERE mplexid = :MPLEXID "
713  "ORDER BY mplexid" );
714  query.bindValue(":MPLEXID", nMplexID);
715 
716  if (!query.exec())
717  {
718  MythDB::DBError("MythAPI::GetVideoMultiplex()", query);
719 
720  throw( QString( "Database Error executing query." ));
721  }
722 
723  auto *pVideoMultiplex = new DTC::VideoMultiplex();
724 
725  if (query.next())
726  {
727  pVideoMultiplex->setMplexId( nMplexID );
728  pVideoMultiplex->setSourceId( query.value(0).toInt() );
729  pVideoMultiplex->setTransportId( query.value(1).toInt() );
730  pVideoMultiplex->setNetworkId( query.value(2).toInt() );
731  pVideoMultiplex->setFrequency( query.value(3).toLongLong() );
732  pVideoMultiplex->setInversion( query.value(4).toString() );
733  pVideoMultiplex->setSymbolRate( query.value(5).toLongLong() );
734  pVideoMultiplex->setFEC( query.value(6).toString() );
735  pVideoMultiplex->setPolarity( query.value(7).toString() );
736  pVideoMultiplex->setModulation( query.value(8).toString() );
737  pVideoMultiplex->setBandwidth( query.value(9).toString() );
738  pVideoMultiplex->setLPCodeRate( query.value(10).toString() );
739  pVideoMultiplex->setTransmissionMode( query.value(11).toString() );
740  pVideoMultiplex->setGuardInterval( query.value(12).toString() );
741  pVideoMultiplex->setVisible( query.value(13).toBool() );
742  pVideoMultiplex->setConstellation( query.value(14).toString() );
743  pVideoMultiplex->setHierarchy( query.value(15).toString() );
744  pVideoMultiplex->setHPCodeRate( query.value(16).toString() );
745  pVideoMultiplex->setModulationSystem( query.value(17).toString() );
746  pVideoMultiplex->setRollOff( query.value(18).toString() );
747  pVideoMultiplex->setSIStandard( query.value(19).toString() );
748  pVideoMultiplex->setServiceVersion( query.value(20).toInt() );
749  pVideoMultiplex->setUpdateTimeStamp(
750  MythDate::as_utc(query.value(21).toDateTime()));
751  pVideoMultiplex->setDefaultAuthority( query.value(22).toString() );
752  }
753 
754  return pVideoMultiplex;
755 }
756 
758 //
760 
762 {
763  MSqlQuery query(MSqlQuery::InitCon());
764 
765  if (!query.isConnected())
766  throw( QString("Database not open while trying to get source name."));
767 
768  query.prepare("SELECT name FROM videosource WHERE sourceid = :SOURCEID ");
769  query.bindValue(":SOURCEID", SourceID);
770 
771  if (!query.exec())
772  {
773  MythDB::DBError("MythAPI::GetXMLTVIdList()", query);
774 
775  throw( QString( "Database Error executing query." ));
776  }
777 
778  QStringList idList;
779 
780  if (query.next())
781  {
782  QString sourceName = query.value(0).toString();
783 
784  QString xmltvFile = GetConfDir() + '/' + sourceName + ".xmltv";
785 
786  if (QFile::exists(xmltvFile))
787  {
788  QFile file(xmltvFile);
789  if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
790  return idList;
791 
792  while (!file.atEnd())
793  {
794  QByteArray line = file.readLine();
795 
796  if (line.startsWith("channel="))
797  {
798  QString id = line.mid(8, -1).trimmed();
799  idList.append(id);
800  }
801  }
802 
803  idList.sort();
804  }
805  }
806  else
807  throw(QString("SourceID (%1) not found").arg(SourceID));
808 
809  return idList;
810 }
ChannelInfo
Definition: channelinfo.h:31
serviceUtil.h
MSqlBindings
QMap< QString, QVariant > MSqlBindings
typedef for a map of string -> string bindings for generic queries.
Definition: mythdbcon.h:101
Channel::FetchChannelsFromSource
int FetchChannelsFromSource(uint SourceId, uint CardId, bool WaitForFinish) override
Definition: channel.cpp:572
MSqlQuery::next
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:807
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:128
ChannelInfo::m_serviceType
uint m_serviceType
Definition: channelinfo.h:112
DTC::VideoSourceList
Definition: videoSourceList.h:15
MSqlQuery::size
int size(void) const
Definition: mythdbcon.h:215
SourceUtil::DeleteSource
static bool DeleteSource(uint sourceid)
Definition: sourceutil.cpp:527
ADD_SQL
static void ADD_SQL(QString &settings_var, MSqlBindings &bindvar, const QString &col, const QString &api_param, const T &val)
Definition: serviceUtil.h:52
Channel::RemoveDBChannel
bool RemoveDBChannel(uint ChannelID) override
Definition: channel.cpp:284
ChannelInfo::m_chanId
uint m_chanId
Definition: channelinfo.h:85
MythDate::as_utc
QDateTime as_utc(const QDateTime &old_dt)
Returns copy of QDateTime with TimeSpec set to UTC.
Definition: mythdate.cpp:27
ChannelUtil::LoadChannels
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, const QString &callsign="", const QString &channum="", bool ignoreUntunable=true)
Load channels from database into a list of ChannelInfo objects.
Definition: channelutil.cpp:2410
SourceUtil::GetChannelCount
static uint GetChannelCount(uint sourceid)
Definition: sourceutil.cpp:133
UseEIT
Definition: videosource.cpp:599
kChannelNeverVisible
@ kChannelNeverVisible
Definition: channelinfo.h:25
channel.h
ChannelUtil::DeleteChannel
static bool DeleteChannel(uint channel_id)
Definition: channelutil.cpp:1767
ChannelInfo::m_freqId
QString m_freqId
Definition: channelinfo.h:87
Channel::GetVideoMultiplexList
DTC::VideoMultiplexList * GetVideoMultiplexList(uint SourceID, uint StartIndex, uint Count) override
Definition: channel.cpp:601
DTC::VideoMultiplex
Definition: videoMultiplex.h:15
ChannelUtil::kChanGroupByChanid
@ kChanGroupByChanid
Definition: channelutil.h:209
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:205
mythdbcon.h
Channel::GetXMLTVIdList
QStringList GetXMLTVIdList(uint SourceID) override
Definition: channel.cpp:761
FillChannelInfo
bool FillChannelInfo(DTC::ChannelInfo *pChannel, uint nChanID, bool bDetails)
Definition: serviceUtil.cpp:175
ChannelInfo::m_atscMajorChan
uint m_atscMajorChan
Definition: channelinfo.h:113
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:608
ChannelInfo::m_name
QString m_name
Definition: channelinfo.h:92
MythDate::Format
Format
Definition: mythdate.h:15
Service::HAS_PARAM
bool HAS_PARAM(const QString &p) const
Definition: service.h:67
Channel::GetVideoMultiplex
DTC::VideoMultiplex * GetVideoMultiplex(uint MplexID) override
Definition: channel.cpp:699
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
SourceID
Definition: videosource.cpp:2873
ChannelUtil::kChanOrderByName
@ kChanOrderByName
Definition: channelutil.h:201
Channel::GetDDLineupList
DTC::LineupList * GetDDLineupList(const QString &, const QString &, const QString &) override
Definition: channel.cpp:560
build_compdb.file
file
Definition: build_compdb.py:55
SourceUtil::CreateSource
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)
Definition: sourceutil.cpp:474
mythdirs.h
DTC::ChannelInfoList
Definition: channelInfoList.h:14
kChannelAlwaysVisible
@ kChannelAlwaysVisible
Definition: channelinfo.h:22
ChannelUtil::CreateChannel
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, ChannelVisibleType visible, const QString &freqid, const QString &icon=QString(), QString format="Default", const QString &xmltvid=QString(), const QString &default_authority=QString(), uint service_type=0)
Definition: channelutil.cpp:1483
Visible
Definition: channelsettings.cpp:392
ChannelInfo::m_icon
QString m_icon
Definition: channelinfo.h:93
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:14
Channel::GetVideoSourceList
DTC::VideoSourceList * GetVideoSourceList(void) override
Definition: channel.cpp:295
Channel::UpdateDBChannel
bool UpdateDBChannel(uint MplexID, uint SourceID, uint ChannelID, const QString &CallSign, const QString &ChannelName, const QString &ChannelNumber, uint ServiceID, uint ATSCMajorChannel, uint ATSCMinorChannel, bool UseEIT, bool Visible, const QString &ExtendedVisible, const QString &FrequencyID, const QString &Icon, const QString &Format, const QString &XMLTVID, const QString &DefaultAuthority, uint ServiceType) override
Definition: channel.cpp:147
mythversion.h
ChannelID
Definition: channelsettings.h:20
SourceUtil::IsSourceIDValid
static bool IsSourceIDValid(uint sourceid)
Definition: sourceutil.cpp:377
Channel::GetChannelInfoList
DTC::ChannelInfoList * GetChannelInfoList(uint SourceID, uint ChannelGroupID, uint StartIndex, uint Count, bool OnlyVisible, bool Details, bool OrderByName, bool GroupByCallsign, bool OnlyTunable) override
Definition: channel.cpp:52
MYTH_PROTO_VERSION
static constexpr const char * MYTH_PROTO_VERSION
Increment this whenever the MythTV network protocol changes.
Definition: mythversion.h:47
ChannelInfo::m_useOnAirGuide
bool m_useOnAirGuide
Definition: channelinfo.h:108
mythdate.h
sourceutil.h
SourceUtil::UpdateChannelsFromListings
static bool UpdateChannelsFromListings(uint sourceid, const QString &inputtype=QString(), bool wait=false)
Definition: sourceutil.cpp:393
ServiceID
Definition: channelsettings.cpp:313
GetConfDir
QString GetConfDir(void)
Definition: mythdirs.cpp:224
channelVisibleTypeFromString
ChannelVisibleType channelVisibleTypeFromString(const QString &type)
Definition: channelinfo.cpp:538
CardUtil::IsEncoder
static bool IsEncoder(const QString &rawtype)
Definition: cardutil.h:130
ChannelInfo::m_atscMinorChan
uint m_atscMinorChan
Definition: channelinfo.h:114
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:540
compat.h
DTC::VideoSource
Definition: videoSource.h:14
DTC::LineupList
Definition: lineup.h:66
MythDB::DBError
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:227
ChannelInfo::m_chanNum
QString m_chanNum
Definition: channelinfo.h:86
Channel::GetVideoSource
DTC::VideoSource * GetVideoSource(uint SourceID) override
Definition: channel.cpp:354
Service::m_parsedParams
QList< QString > m_parsedParams
Definition: service.h:68
MSqlQuery::seek
bool seek(int where, bool relative=false)
Wrap QSqlQuery::seek(int,bool)
Definition: mythdbcon.cpp:827
ChannelVisibleType
ChannelVisibleType
Definition: channelinfo.h:20
MYTH_BINARY_VERSION
static constexpr const char * MYTH_BINARY_VERSION
Update this whenever the plug-in ABI changes.
Definition: mythversion.h:15
MSqlQuery::isConnected
bool isConnected(void) const
Only updated once during object creation.
Definition: mythdbcon.h:138
uint
unsigned int uint
Definition: compat.h:79
channelutil.h
Channel::UpdateVideoSource
bool UpdateVideoSource(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) override
Definition: channel.cpp:408
ChannelUtil::UpdateChannel
static bool UpdateChannel(uint db_mplexid, uint source_id, uint 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, ChannelVisibleType visible, const QString &freqid=QString(), const QString &icon=QString(), QString format=QString(), const QString &xmltvid=QString(), const QString &default_authority=QString(), uint service_type=0)
Definition: channelutil.cpp:1563
CardUtil::GetRawInputType
static QString GetRawInputType(uint inputid)
Definition: cardutil.h:287
ChannelInfo::m_serviceId
uint m_serviceId
Definition: channelinfo.h:111
kChannelVisible
@ kChannelVisible
Definition: channelinfo.h:23
mythcorecontext.h
cardutil.h
ChannelInfo::Load
bool Load(uint lchanid=-1)
Definition: channelinfo.cpp:130
MSqlQuery::bindValue
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:883
ChannelInfo::m_sourceId
uint m_sourceId
Definition: channelinfo.h:89
ChannelInfo::m_tvFormat
QString m_tvFormat
Definition: channelinfo.h:105
ChannelInfo::m_xmltvId
QString m_xmltvId
Definition: channelinfo.h:97
Channel::RemoveVideoSource
bool RemoveVideoSource(uint SourceID) override
Definition: channel.cpp:549
Icon
Definition: channelsettings.cpp:209
DTC::VideoMultiplexList
Definition: videoMultiplexList.h:15
DTC::ChannelInfo
Definition: programAndChannel.h:30
CardUtil::IsUnscanable
static bool IsUnscanable(const QString &rawtype)
Definition: cardutil.h:153
Channel::AddVideoSource
int AddVideoSource(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) override
Definition: channel.cpp:523
ChannelInfo::m_mplexId
uint m_mplexId
Definition: channelinfo.h:110
Channel::AddDBChannel
bool AddDBChannel(uint MplexID, uint SourceID, uint ChannelID, const QString &CallSign, const QString &ChannelName, const QString &ChannelNumber, uint ServiceID, uint ATSCMajorChannel, uint ATSCMinorChannel, bool UseEIT, bool Visible, const QString &ExtendedVisible, const QString &FrequencyID, const QString &Icon, const QString &Format, const QString &XMLTVID, const QString &DefaultAuthority, uint ServiceType) override
Definition: channel.cpp:242
ChannelInfo::m_visible
ChannelVisibleType m_visible
Definition: channelinfo.h:106
Channel::GetChannelInfo
DTC::ChannelInfo * GetChannelInfo(uint ChanID) override
Definition: channel.cpp:130
ChannelInfo::m_defaultAuthority
QString m_defaultAuthority
Definition: channelinfo.h:118
ChannelInfo::m_callSign
QString m_callSign
Definition: channelinfo.h:91
ChannelUtil::kChanOrderByChanNum
@ kChanOrderByChanNum
Definition: channelutil.h:200
ChannelUtil::kChanGroupByCallsign
@ kChanGroupByCallsign
Definition: channelutil.h:207
kChannelNotVisible
@ kChannelNotVisible
Definition: channelinfo.h:24
MSqlQuery::prepare
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:832
ChannelInfoList
std::vector< ChannelInfo > ChannelInfoList
Definition: channelinfo.h:131