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  if (HAS_PARAM("extendedvisible"))
192  channel.m_visible = channelVisibleTypeFromString(ExtendedVisible);
193  else if (HAS_PARAM("visible"))
194  {
195  if (channel.m_visible == kChannelVisible ||
196  channel.m_visible == kChannelNotVisible)
197  {
198  channel.m_visible =
200  }
201  else if ((channel.m_visible == kChannelAlwaysVisible && !Visible) ||
202  (channel.m_visible == kChannelNeverVisible && Visible))
203  {
204  throw QString("Can't override Always/NeverVisible");
205  }
206  }
207  if (HAS_PARAM("frequencyid"))
208  channel.m_freqId = FrequencyID;
209  if (HAS_PARAM("icon"))
210  channel.m_icon = Icon;
211  if (HAS_PARAM("format"))
212  channel.m_tvFormat = Format;
213  if (HAS_PARAM("xmltvid"))
214  channel.m_xmltvId = XMLTVID;
215  if (HAS_PARAM("defaultauthority"))
216  channel.m_defaultAuthority = DefaultAuthority;
217  if (HAS_PARAM("servicetype"))
218  channel.m_serviceType = ServiceType;
219 
220  bool bResult = ChannelUtil::UpdateChannel(
221  channel.m_mplexId, channel.m_sourceId, channel.m_chanId,
222  channel.m_callSign, channel.m_name, channel.m_chanNum,
223  channel.m_serviceId, channel.m_atscMajorChan,
224  channel.m_atscMinorChan, channel.m_useOnAirGuide,
225  channel.m_visible, channel.m_freqId,
226  channel.m_icon, channel.m_tvFormat, channel.m_xmltvId,
227  channel.m_defaultAuthority, channel.m_serviceType );
228 
229  return bResult;
230 }
231 
233  uint SourceID,
234  uint ChannelID,
235  const QString &CallSign,
236  const QString &ChannelName,
237  const QString &ChannelNumber,
238  uint ServiceID,
239  uint ATSCMajorChannel,
240  uint ATSCMinorChannel,
241  bool UseEIT,
242  bool Visible,
243  const QString &ExtendedVisible,
244  const QString &FrequencyID,
245  const QString &Icon,
246  const QString &Format,
247  const QString &XMLTVID,
248  const QString &DefaultAuthority,
249  uint ServiceType )
250 {
251  ChannelVisibleType chan_visible = kChannelVisible;
252  if (HAS_PARAM("extendedvisible"))
253  chan_visible = channelVisibleTypeFromString(ExtendedVisible);
254  else if (HAS_PARAM("visible"))
255  chan_visible = (Visible ? kChannelVisible : kChannelNotVisible);
256 
257  bool bResult = ChannelUtil::CreateChannel( MplexID, SourceID, ChannelID,
258  CallSign, ChannelName, ChannelNumber,
259  ServiceID, ATSCMajorChannel, ATSCMinorChannel,
260  UseEIT, chan_visible, FrequencyID,
261  Icon, Format, XMLTVID, DefaultAuthority,
262  ServiceType );
263 
264  return bResult;
265 }
266 
267 bool Channel::RemoveDBChannel( uint nChannelID )
268 {
269  bool bResult = ChannelUtil::DeleteChannel( nChannelID );
270 
271  return bResult;
272 }
273 
275 //
277 
279 {
280  MSqlQuery query(MSqlQuery::InitCon());
281 
282  if (!query.isConnected())
283  throw( QString("Database not open while trying to list "
284  "Video Sources."));
285 
286  query.prepare("SELECT sourceid, name, xmltvgrabber, userid, "
287  "freqtable, lineupid, password, useeit, configpath, "
288  "dvb_nit_id, bouquet_id, region_id, scanfrequency, "
289  "lcnoffset FROM videosource "
290  "ORDER BY sourceid" );
291 
292  if (!query.exec())
293  {
294  MythDB::DBError("MythAPI::GetVideoSourceList()", query);
295 
296  throw( QString( "Database Error executing query." ));
297  }
298 
299  // ----------------------------------------------------------------------
300  // return the results of the query
301  // ----------------------------------------------------------------------
302 
303  auto* pList = new DTC::VideoSourceList();
304 
305  while (query.next())
306  {
307 
308  DTC::VideoSource *pVideoSource = pList->AddNewVideoSource();
309 
310  pVideoSource->setId ( query.value(0).toInt() );
311  pVideoSource->setSourceName ( query.value(1).toString() );
312  pVideoSource->setGrabber ( query.value(2).toString() );
313  pVideoSource->setUserId ( query.value(3).toString() );
314  pVideoSource->setFreqTable ( query.value(4).toString() );
315  pVideoSource->setLineupId ( query.value(5).toString() );
316  pVideoSource->setPassword ( query.value(6).toString() );
317  pVideoSource->setUseEIT ( query.value(7).toBool() );
318  pVideoSource->setConfigPath ( query.value(8).toString() );
319  pVideoSource->setNITId ( query.value(9).toInt() );
320  pVideoSource->setBouquetId ( query.value(10).toUInt() );
321  pVideoSource->setRegionId ( query.value(11).toUInt() );
322  pVideoSource->setScanFrequency ( query.value(12).toUInt() );
323  pVideoSource->setLCNOffset ( query.value(13).toUInt() );
324  }
325 
326  pList->setAsOf ( MythDate::current() );
327  pList->setVersion ( MYTH_BINARY_VERSION );
328  pList->setProtoVer ( MYTH_PROTO_VERSION );
329 
330  return pList;
331 }
332 
334 //
336 
338 {
339  MSqlQuery query(MSqlQuery::InitCon());
340 
341  if (!query.isConnected())
342  throw( QString("Database not open while trying to list "
343  "Video Sources."));
344 
345  query.prepare("SELECT name, xmltvgrabber, userid, "
346  "freqtable, lineupid, password, useeit, configpath, "
347  "dvb_nit_id, bouquet_id, region_id, scanfrequency, "
348  "lcnoffset "
349  "FROM videosource WHERE sourceid = :SOURCEID "
350  "ORDER BY sourceid" );
351  query.bindValue(":SOURCEID", nSourceID);
352 
353  if (!query.exec())
354  {
355  MythDB::DBError("MythAPI::GetVideoSource()", query);
356 
357  throw( QString( "Database Error executing query." ));
358  }
359 
360  // ----------------------------------------------------------------------
361  // return the results of the query
362  // ----------------------------------------------------------------------
363 
364  auto *pVideoSource = new DTC::VideoSource();
365 
366  if (query.next())
367  {
368  pVideoSource->setId ( nSourceID );
369  pVideoSource->setSourceName ( query.value(0).toString() );
370  pVideoSource->setGrabber ( query.value(1).toString() );
371  pVideoSource->setUserId ( query.value(2).toString() );
372  pVideoSource->setFreqTable ( query.value(3).toString() );
373  pVideoSource->setLineupId ( query.value(4).toString() );
374  pVideoSource->setPassword ( query.value(5).toString() );
375  pVideoSource->setUseEIT ( query.value(6).toBool() );
376  pVideoSource->setConfigPath ( query.value(7).toString() );
377  pVideoSource->setNITId ( query.value(8).toInt() );
378  pVideoSource->setBouquetId ( query.value(9).toUInt() );
379  pVideoSource->setRegionId ( query.value(10).toUInt() );
380  pVideoSource->setScanFrequency ( query.value(11).toUInt() );
381  pVideoSource->setLCNOffset ( query.value(12).toUInt() );
382  }
383 
384  return pVideoSource;
385 }
386 
388 //
390 
392  const QString &sSourceName,
393  const QString &sGrabber,
394  const QString &sUserId,
395  const QString &sFreqTable,
396  const QString &sLineupId,
397  const QString &sPassword,
398  bool bUseEIT,
399  const QString &sConfigPath,
400  int nNITId,
401  uint nBouquetId,
402  uint nRegionId,
403  uint nScanFrequency,
404  uint nLCNOffset )
405 {
406 
407  if (!HAS_PARAM("sourceid"))
408  {
409  LOG(VB_GENERAL, LOG_ERR, "SourceId is required");
410  return false;
411  }
412 
413  if (!SourceUtil::IsSourceIDValid(nSourceId))
414  {
415  LOG(VB_GENERAL, LOG_ERR, QString("SourceId %1 doesn't exist")
416  .arg(nSourceId));
417  return false;
418  }
419 
420  if (m_parsedParams.size() < 2 )
421  {
422  LOG(VB_GENERAL, LOG_ERR, QString("SourceId=%1 was the only parameter")
423  .arg(nSourceId));
424  return false;
425  }
426 
427  MSqlBindings bindings;
428  MSqlBindings::const_iterator it;
429  QString settings;
430 
431  if ( HAS_PARAM("sourcename") )
432  ADD_SQL(settings, bindings, "name", "SourceName", sSourceName)
433 
434  if ( HAS_PARAM("grabber") )
435  ADD_SQL(settings, bindings, "xmltvgrabber", "Grabber", sGrabber)
436 
437  if ( HAS_PARAM("userid") )
438  ADD_SQL(settings, bindings, "userid", "UserId", sUserId)
439 
440  if ( HAS_PARAM("freqtable") )
441  ADD_SQL(settings, bindings, "freqtable", "FreqTable", sFreqTable)
442 
443  if ( HAS_PARAM("lineupid") )
444  ADD_SQL(settings, bindings, "lineupid", "LineupId", sLineupId)
445 
446  if ( HAS_PARAM("password") )
447  ADD_SQL(settings, bindings, "password", "Password", sPassword)
448 
449  if ( HAS_PARAM("useeit") )
450  ADD_SQL(settings, bindings, "useeit", "UseEIT", bUseEIT)
451 
452  if (HAS_PARAM("configpath"))
453  {
454  if (sConfigPath.isEmpty())
455  settings += "configpath=NULL, "; // mythfilldatabase grabber requirement
456  else
457  ADD_SQL(settings, bindings, "configpath", "ConfigPath", sConfigPath)
458  }
459 
460  if ( HAS_PARAM("nitid") )
461  ADD_SQL(settings, bindings, "dvb_nit_id", "NITId", nNITId)
462 
463  if ( HAS_PARAM("bouquetid") )
464  ADD_SQL(settings, bindings, "bouquet_id", "BouquetId", nBouquetId)
465 
466  if ( HAS_PARAM("regionid") )
467  ADD_SQL(settings, bindings, "region_id", "RegionId", nRegionId)
468 
469  if ( HAS_PARAM("scanfrequency") )
470  ADD_SQL(settings, bindings, "scanfrequency", "ScanFrequency", nScanFrequency)
471 
472  if ( HAS_PARAM("lcnoffset") )
473  ADD_SQL(settings, bindings, "lcnoffset", "LCNOffset", nLCNOffset)
474 
475  if ( settings.isEmpty() )
476  {
477  LOG(VB_GENERAL, LOG_ERR, "No valid parameters were passed");
478  return false;
479  }
480 
481  settings.chop(2);
482 
483  MSqlQuery query(MSqlQuery::InitCon());
484 
485  query.prepare(QString("UPDATE videosource SET %1 WHERE sourceid=:SOURCEID")
486  .arg(settings));
487  bindings[":SOURCEID"] = nSourceId;
488 
489  for (it = bindings.cbegin(); it != bindings.cend(); ++it)
490  query.bindValue(it.key(), it.value());
491 
492  if (!query.exec())
493  {
494  MythDB::DBError("MythAPI::UpdateVideoSource()", query);
495 
496  throw( QString( "Database Error executing query." ));
497  }
498 
499  return true;
500 }
501 
503 //
505 
506 int Channel::AddVideoSource( const QString &sSourceName,
507  const QString &sGrabber,
508  const QString &sUserId,
509  const QString &sFreqTable,
510  const QString &sLineupId,
511  const QString &sPassword,
512  bool bUseEIT,
513  const QString &sConfigPath,
514  int nNITId,
515  uint nBouquetId,
516  uint nRegionId,
517  uint nScanFrequency,
518  uint nLCNOffset )
519 {
520  int nResult = SourceUtil::CreateSource(sSourceName, sGrabber, sUserId, sFreqTable,
521  sLineupId, sPassword, bUseEIT, sConfigPath,
522  nNITId, nBouquetId, nRegionId, nScanFrequency,
523  nLCNOffset);
524 
525  return nResult;
526 }
527 
529 //
531 
533 {
534  bool bResult = SourceUtil::DeleteSource( nSourceID );
535 
536  return bResult;
537 }
538 
540 //
542 
543 DTC::LineupList* Channel::GetDDLineupList( const QString &/*sSource*/,
544  const QString &/*sUserId*/,
545  const QString &/*sPassword*/ )
546 {
547  auto *pLineups = new DTC::LineupList();
548  return pLineups;
549 }
550 
552 //
554 
556  const uint nCardId,
557  bool bWaitForFinish )
558 {
559  if ( nSourceId < 1 || nCardId < 1)
560  throw( QString("A source ID and card ID are both required."));
561 
562  int nResult = 0;
563 
564  QString cardtype = CardUtil::GetRawInputType(nCardId);
565 
566  if (!CardUtil::IsUnscanable(cardtype) &&
567  !CardUtil::IsEncoder(cardtype))
568  {
569  throw( QString("This device is incompatible with channel fetching.") );
570  }
571 
572  SourceUtil::UpdateChannelsFromListings(nSourceId, cardtype, bWaitForFinish);
573 
574  if (bWaitForFinish)
575  nResult = SourceUtil::GetChannelCount(nSourceId);
576 
577  return nResult;
578 }
579 
581 //
583 
585  uint nStartIndex,
586  uint nCount )
587 {
588  MSqlQuery query(MSqlQuery::InitCon());
589 
590  if (!query.isConnected())
591  throw( QString("Database not open while trying to list "
592  "Video Sources."));
593 
594  query.prepare("SELECT mplexid, sourceid, transportid, networkid, "
595  "frequency, inversion, symbolrate, fec, polarity, "
596  "modulation, bandwidth, lp_code_rate, transmission_mode, "
597  "guard_interval, visible, constellation, hierarchy, hp_code_rate, "
598  "mod_sys, rolloff, sistandard, serviceversion, updatetimestamp, "
599  "default_authority FROM dtv_multiplex WHERE sourceid = :SOURCEID "
600  "ORDER BY mplexid" );
601  query.bindValue(":SOURCEID", nSourceID);
602 
603  if (!query.exec())
604  {
605  MythDB::DBError("MythAPI::GetVideoMultiplexList()", query);
606 
607  throw( QString( "Database Error executing query." ));
608  }
609 
610  uint muxCount = (uint)query.size();
611 
612  // ----------------------------------------------------------------------
613  // Build Response
614  // ----------------------------------------------------------------------
615 
616  auto *pVideoMultiplexes = new DTC::VideoMultiplexList();
617 
618  nStartIndex = (nStartIndex > 0) ? std::min( nStartIndex, muxCount ) : 0;
619  nCount = (nCount > 0) ? std::min( nCount, muxCount ) : muxCount;
620  int nEndIndex = std::min((nStartIndex + nCount), muxCount );
621 
622  for( int n = nStartIndex; n < nEndIndex; n++)
623  {
624  if (query.seek(n))
625  {
626  DTC::VideoMultiplex *pVideoMultiplex = pVideoMultiplexes->AddNewVideoMultiplex();
627 
628  pVideoMultiplex->setMplexId( query.value(0).toInt() );
629  pVideoMultiplex->setSourceId( query.value(1).toInt() );
630  pVideoMultiplex->setTransportId( query.value(2).toInt() );
631  pVideoMultiplex->setNetworkId( query.value(3).toInt() );
632  pVideoMultiplex->setFrequency( query.value(4).toLongLong() );
633  pVideoMultiplex->setInversion( query.value(5).toString() );
634  pVideoMultiplex->setSymbolRate( query.value(6).toLongLong() );
635  pVideoMultiplex->setFEC( query.value(7).toString() );
636  pVideoMultiplex->setPolarity( query.value(8).toString() );
637  pVideoMultiplex->setModulation( query.value(9).toString() );
638  pVideoMultiplex->setBandwidth( query.value(10).toString() );
639  pVideoMultiplex->setLPCodeRate( query.value(11).toString() );
640  pVideoMultiplex->setTransmissionMode( query.value(12).toString() );
641  pVideoMultiplex->setGuardInterval( query.value(13).toString() );
642  pVideoMultiplex->setVisible( query.value(14).toBool() );
643  pVideoMultiplex->setConstellation( query.value(15).toString() );
644  pVideoMultiplex->setHierarchy( query.value(16).toString() );
645  pVideoMultiplex->setHPCodeRate( query.value(17).toString() );
646  pVideoMultiplex->setModulationSystem( query.value(18).toString() );
647  pVideoMultiplex->setRollOff( query.value(19).toString() );
648  pVideoMultiplex->setSIStandard( query.value(20).toString() );
649  pVideoMultiplex->setServiceVersion( query.value(21).toInt() );
650  pVideoMultiplex->setUpdateTimeStamp(
651  MythDate::as_utc(query.value(22).toDateTime()));
652  pVideoMultiplex->setDefaultAuthority( query.value(23).toString() );
653  }
654  }
655 
656  int curPage = 0;
657  int totalPages = 0;
658  if (nCount == 0)
659  totalPages = 1;
660  else
661  totalPages = (int)std::ceil((float)muxCount / nCount);
662 
663  if (totalPages == 1)
664  curPage = 1;
665  else
666  {
667  curPage = (int)std::ceil((float)nStartIndex / nCount) + 1;
668  }
669 
670  pVideoMultiplexes->setStartIndex ( nStartIndex );
671  pVideoMultiplexes->setCount ( nCount );
672  pVideoMultiplexes->setCurrentPage ( curPage );
673  pVideoMultiplexes->setTotalPages ( totalPages );
674  pVideoMultiplexes->setTotalAvailable( muxCount );
675  pVideoMultiplexes->setAsOf ( MythDate::current() );
676  pVideoMultiplexes->setVersion ( MYTH_BINARY_VERSION );
677  pVideoMultiplexes->setProtoVer ( MYTH_PROTO_VERSION );
678 
679  return pVideoMultiplexes;
680 }
681 
683 {
684  MSqlQuery query(MSqlQuery::InitCon());
685 
686  if (!query.isConnected())
687  throw( QString("Database not open while trying to list "
688  "Video Multiplex."));
689 
690  query.prepare("SELECT sourceid, transportid, networkid, "
691  "frequency, inversion, symbolrate, fec, polarity, "
692  "modulation, bandwidth, lp_code_rate, transmission_mode, "
693  "guard_interval, visible, constellation, hierarchy, hp_code_rate, "
694  "mod_sys, rolloff, sistandard, serviceversion, updatetimestamp, "
695  "default_authority FROM dtv_multiplex WHERE mplexid = :MPLEXID "
696  "ORDER BY mplexid" );
697  query.bindValue(":MPLEXID", nMplexID);
698 
699  if (!query.exec())
700  {
701  MythDB::DBError("MythAPI::GetVideoMultiplex()", query);
702 
703  throw( QString( "Database Error executing query." ));
704  }
705 
706  auto *pVideoMultiplex = new DTC::VideoMultiplex();
707 
708  if (query.next())
709  {
710  pVideoMultiplex->setMplexId( nMplexID );
711  pVideoMultiplex->setSourceId( query.value(0).toInt() );
712  pVideoMultiplex->setTransportId( query.value(1).toInt() );
713  pVideoMultiplex->setNetworkId( query.value(2).toInt() );
714  pVideoMultiplex->setFrequency( query.value(3).toLongLong() );
715  pVideoMultiplex->setInversion( query.value(4).toString() );
716  pVideoMultiplex->setSymbolRate( query.value(5).toLongLong() );
717  pVideoMultiplex->setFEC( query.value(6).toString() );
718  pVideoMultiplex->setPolarity( query.value(7).toString() );
719  pVideoMultiplex->setModulation( query.value(8).toString() );
720  pVideoMultiplex->setBandwidth( query.value(9).toString() );
721  pVideoMultiplex->setLPCodeRate( query.value(10).toString() );
722  pVideoMultiplex->setTransmissionMode( query.value(11).toString() );
723  pVideoMultiplex->setGuardInterval( query.value(12).toString() );
724  pVideoMultiplex->setVisible( query.value(13).toBool() );
725  pVideoMultiplex->setConstellation( query.value(14).toString() );
726  pVideoMultiplex->setHierarchy( query.value(15).toString() );
727  pVideoMultiplex->setHPCodeRate( query.value(16).toString() );
728  pVideoMultiplex->setModulationSystem( query.value(17).toString() );
729  pVideoMultiplex->setRollOff( query.value(18).toString() );
730  pVideoMultiplex->setSIStandard( query.value(19).toString() );
731  pVideoMultiplex->setServiceVersion( query.value(20).toInt() );
732  pVideoMultiplex->setUpdateTimeStamp(
733  MythDate::as_utc(query.value(21).toDateTime()));
734  pVideoMultiplex->setDefaultAuthority( query.value(22).toString() );
735  }
736 
737  return pVideoMultiplex;
738 }
739 
741 //
743 
745 {
746  MSqlQuery query(MSqlQuery::InitCon());
747 
748  if (!query.isConnected())
749  throw( QString("Database not open while trying to get source name."));
750 
751  query.prepare("SELECT name FROM videosource WHERE sourceid = :SOURCEID ");
752  query.bindValue(":SOURCEID", SourceID);
753 
754  if (!query.exec())
755  {
756  MythDB::DBError("MythAPI::GetXMLTVIdList()", query);
757 
758  throw( QString( "Database Error executing query." ));
759  }
760 
761  QStringList idList;
762 
763  if (query.next())
764  {
765  QString sourceName = query.value(0).toString();
766 
767  QString xmltvFile = GetConfDir() + '/' + sourceName + ".xmltv";
768 
769  if (QFile::exists(xmltvFile))
770  {
771  QFile file(xmltvFile);
772  if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
773  return idList;
774 
775  while (!file.atEnd())
776  {
777  QByteArray line = file.readLine();
778 
779  if (line.startsWith("channel="))
780  {
781  QString id = line.mid(8, -1).trimmed();
782  idList.append(id);
783  }
784  }
785 
786  idList.sort();
787  }
788  }
789  else
790  throw(QString("SourceID (%1) not found").arg(SourceID));
791 
792  return idList;
793 }
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:555
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:267
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:584
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:744
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:682
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:543
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:278
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:337
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:140
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:391
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:532
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:506
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:232
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