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