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