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