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 
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 {
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 FROM videosource "
289  "ORDER BY sourceid" );
290 
291  if (!query.exec())
292  {
293  MythDB::DBError("MythAPI::GetVideoSourceList()", query);
294 
295  throw( QString( "Database Error executing query." ));
296  }
297 
298  // ----------------------------------------------------------------------
299  // return the results of the query
300  // ----------------------------------------------------------------------
301 
302  auto* pList = new DTC::VideoSourceList();
303 
304  while (query.next())
305  {
306 
307  DTC::VideoSource *pVideoSource = pList->AddNewVideoSource();
308 
309  pVideoSource->setId ( query.value(0).toInt() );
310  pVideoSource->setSourceName ( query.value(1).toString() );
311  pVideoSource->setGrabber ( query.value(2).toString() );
312  pVideoSource->setUserId ( query.value(3).toString() );
313  pVideoSource->setFreqTable ( query.value(4).toString() );
314  pVideoSource->setLineupId ( query.value(5).toString() );
315  pVideoSource->setPassword ( query.value(6).toString() );
316  pVideoSource->setUseEIT ( query.value(7).toBool() );
317  pVideoSource->setConfigPath ( query.value(8).toString() );
318  pVideoSource->setNITId ( query.value(9).toInt() );
319  pVideoSource->setBouquetId ( query.value(10).toUInt() );
320  pVideoSource->setRegionId ( query.value(11).toUInt() );
321  pVideoSource->setScanFrequency ( query.value(12).toUInt() );
322  }
323 
324  pList->setAsOf ( MythDate::current() );
325  pList->setVersion ( MYTH_BINARY_VERSION );
326  pList->setProtoVer ( MYTH_PROTO_VERSION );
327 
328  return pList;
329 }
330 
332 //
334 
336 {
338 
339  if (!query.isConnected())
340  throw( QString("Database not open while trying to list "
341  "Video Sources."));
342 
343  query.prepare("SELECT name, xmltvgrabber, userid, "
344  "freqtable, lineupid, password, useeit, configpath, "
345  "dvb_nit_id, bouquet_id, region_id, scanfrequency "
346  "FROM videosource WHERE sourceid = :SOURCEID "
347  "ORDER BY sourceid" );
348  query.bindValue(":SOURCEID", nSourceID);
349 
350  if (!query.exec())
351  {
352  MythDB::DBError("MythAPI::GetVideoSource()", query);
353 
354  throw( QString( "Database Error executing query." ));
355  }
356 
357  // ----------------------------------------------------------------------
358  // return the results of the query
359  // ----------------------------------------------------------------------
360 
361  auto *pVideoSource = new DTC::VideoSource();
362 
363  if (query.next())
364  {
365  pVideoSource->setId ( nSourceID );
366  pVideoSource->setSourceName ( query.value(0).toString() );
367  pVideoSource->setGrabber ( query.value(1).toString() );
368  pVideoSource->setUserId ( query.value(2).toString() );
369  pVideoSource->setFreqTable ( query.value(3).toString() );
370  pVideoSource->setLineupId ( query.value(4).toString() );
371  pVideoSource->setPassword ( query.value(5).toString() );
372  pVideoSource->setUseEIT ( query.value(6).toBool() );
373  pVideoSource->setConfigPath ( query.value(7).toString() );
374  pVideoSource->setNITId ( query.value(8).toInt() );
375  pVideoSource->setBouquetId ( query.value(9).toUInt() );
376  pVideoSource->setRegionId ( query.value(10).toUInt() );
377  pVideoSource->setScanFrequency ( query.value(11).toUInt() );
378  }
379 
380  return pVideoSource;
381 }
382 
384 //
386 
388  const QString &sSourceName,
389  const QString &sGrabber,
390  const QString &sUserId,
391  const QString &sFreqTable,
392  const QString &sLineupId,
393  const QString &sPassword,
394  bool bUseEIT,
395  const QString &sConfigPath,
396  int nNITId,
397  uint nBouquetId,
398  uint nRegionId,
399  uint nScanFrequency )
400 {
401 
402  if (!HAS_PARAM("sourceid"))
403  {
404  LOG(VB_GENERAL, LOG_ERR, "SourceId is required");
405  return false;
406  }
407 
408  if (!SourceUtil::IsSourceIDValid(nSourceId))
409  {
410  LOG(VB_GENERAL, LOG_ERR, QString("SourceId %1 doesn't exist")
411  .arg(nSourceId));
412  return false;
413  }
414 
415  if (m_parsedParams.size() < 2 )
416  {
417  LOG(VB_GENERAL, LOG_ERR, QString("SourceId=%1 was the only parameter")
418  .arg(nSourceId));
419  return false;
420  }
421 
422  MSqlBindings bindings;
423  MSqlBindings::const_iterator it;
424  QString settings;
425 
426  if ( HAS_PARAM("sourcename") )
427  ADD_SQL(settings, bindings, "name", "SourceName", sSourceName)
428 
429  if ( HAS_PARAM("grabber") )
430  ADD_SQL(settings, bindings, "xmltvgrabber", "Grabber", sGrabber)
431 
432  if ( HAS_PARAM("userid") )
433  ADD_SQL(settings, bindings, "userid", "UserId", sUserId)
434 
435  if ( HAS_PARAM("freqtable") )
436  ADD_SQL(settings, bindings, "freqtable", "FreqTable", sFreqTable)
437 
438  if ( HAS_PARAM("lineupid") )
439  ADD_SQL(settings, bindings, "lineupid", "LineupId", sLineupId)
440 
441  if ( HAS_PARAM("password") )
442  ADD_SQL(settings, bindings, "password", "Password", sPassword)
443 
444  if ( HAS_PARAM("useeit") )
445  ADD_SQL(settings, bindings, "useeit", "UseEIT", bUseEIT)
446 
447  if (HAS_PARAM("configpath"))
448  {
449  if (sConfigPath.isEmpty())
450  settings += "configpath=NULL, "; // mythfilldatabase grabber requirement
451  else
452  ADD_SQL(settings, bindings, "configpath", "ConfigPath", sConfigPath)
453  }
454 
455  if ( HAS_PARAM("nitid") )
456  ADD_SQL(settings, bindings, "dvb_nit_id", "NITId", nNITId)
457 
458  if ( HAS_PARAM("bouquetid") )
459  ADD_SQL(settings, bindings, "bouquet_id", "BouquetId", nBouquetId)
460 
461  if ( HAS_PARAM("regionid") )
462  ADD_SQL(settings, bindings, "region_id", "RegionId", nRegionId)
463 
464  if ( HAS_PARAM("scanfrequency") )
465  ADD_SQL(settings, bindings, "scanfrequency", "ScanFrequency", nScanFrequency)
466 
467  if ( settings.isEmpty() )
468  {
469  LOG(VB_GENERAL, LOG_ERR, "No valid parameters were passed");
470  return false;
471  }
472 
473  settings.chop(2);
474 
476 
477  query.prepare(QString("UPDATE videosource SET %1 WHERE sourceid=:SOURCEID")
478  .arg(settings));
479  bindings[":SOURCEID"] = nSourceId;
480 
481  for (it = bindings.begin(); it != bindings.end(); ++it)
482  query.bindValue(it.key(), it.value());
483 
484  if (!query.exec())
485  {
486  MythDB::DBError("MythAPI::UpdateVideoSource()", query);
487 
488  throw( QString( "Database Error executing query." ));
489  }
490 
491  return true;
492 }
493 
495 //
497 
498 int Channel::AddVideoSource( const QString &sSourceName,
499  const QString &sGrabber,
500  const QString &sUserId,
501  const QString &sFreqTable,
502  const QString &sLineupId,
503  const QString &sPassword,
504  bool bUseEIT,
505  const QString &sConfigPath,
506  int nNITId,
507  uint nBouquetId,
508  uint nRegionId,
509  uint nScanFrequency )
510 {
511  int nResult = SourceUtil::CreateSource(sSourceName, sGrabber, sUserId, sFreqTable,
512  sLineupId, sPassword, bUseEIT, sConfigPath,
513  nNITId, nBouquetId, nRegionId, nScanFrequency);
514 
515  return nResult;
516 }
517 
519 //
521 
523 {
524  bool bResult = SourceUtil::DeleteSource( nSourceID );
525 
526  return bResult;
527 }
528 
530 //
532 
533 DTC::LineupList* Channel::GetDDLineupList( const QString &/*sSource*/,
534  const QString &/*sUserId*/,
535  const QString &/*sPassword*/ )
536 {
537  auto *pLineups = new DTC::LineupList();
538  return pLineups;
539 }
540 
542 //
544 
546  const uint nCardId,
547  bool bWaitForFinish )
548 {
549  if ( nSourceId < 1 || nCardId < 1)
550  throw( QString("A source ID and card ID are both required."));
551 
552  int nResult = 0;
553 
554  QString cardtype = CardUtil::GetRawInputType(nCardId);
555 
556  if (!CardUtil::IsUnscanable(cardtype) &&
557  !CardUtil::IsEncoder(cardtype))
558  {
559  throw( QString("This device is incompatible with channel fetching.") );
560  }
561 
562  SourceUtil::UpdateChannelsFromListings(nSourceId, cardtype, bWaitForFinish);
563 
564  if (bWaitForFinish)
565  nResult = SourceUtil::GetChannelCount(nSourceId);
566 
567  return nResult;
568 }
569 
571 //
573 
575  uint nStartIndex,
576  uint nCount )
577 {
579 
580  if (!query.isConnected())
581  throw( QString("Database not open while trying to list "
582  "Video Sources."));
583 
584  query.prepare("SELECT mplexid, sourceid, transportid, networkid, "
585  "frequency, inversion, symbolrate, fec, polarity, "
586  "modulation, bandwidth, lp_code_rate, transmission_mode, "
587  "guard_interval, visible, constellation, hierarchy, hp_code_rate, "
588  "mod_sys, rolloff, sistandard, serviceversion, updatetimestamp, "
589  "default_authority FROM dtv_multiplex WHERE sourceid = :SOURCEID "
590  "ORDER BY mplexid" );
591  query.bindValue(":SOURCEID", nSourceID);
592 
593  if (!query.exec())
594  {
595  MythDB::DBError("MythAPI::GetVideoMultiplexList()", query);
596 
597  throw( QString( "Database Error executing query." ));
598  }
599 
600  uint muxCount = (uint)query.size();
601 
602  // ----------------------------------------------------------------------
603  // Build Response
604  // ----------------------------------------------------------------------
605 
606  auto *pVideoMultiplexes = new DTC::VideoMultiplexList();
607 
608  nStartIndex = (nStartIndex > 0) ? min( nStartIndex, muxCount ) : 0;
609  nCount = (nCount > 0) ? min( nCount, muxCount ) : muxCount;
610  int nEndIndex = min((nStartIndex + nCount), muxCount );
611 
612  for( int n = nStartIndex; n < nEndIndex; n++)
613  {
614  if (query.seek(n))
615  {
616  DTC::VideoMultiplex *pVideoMultiplex = pVideoMultiplexes->AddNewVideoMultiplex();
617 
618  pVideoMultiplex->setMplexId( query.value(0).toInt() );
619  pVideoMultiplex->setSourceId( query.value(1).toInt() );
620  pVideoMultiplex->setTransportId( query.value(2).toInt() );
621  pVideoMultiplex->setNetworkId( query.value(3).toInt() );
622  pVideoMultiplex->setFrequency( query.value(4).toLongLong() );
623  pVideoMultiplex->setInversion( query.value(5).toString() );
624  pVideoMultiplex->setSymbolRate( query.value(6).toLongLong() );
625  pVideoMultiplex->setFEC( query.value(7).toString() );
626  pVideoMultiplex->setPolarity( query.value(8).toString() );
627  pVideoMultiplex->setModulation( query.value(9).toString() );
628  pVideoMultiplex->setBandwidth( query.value(10).toString() );
629  pVideoMultiplex->setLPCodeRate( query.value(11).toString() );
630  pVideoMultiplex->setTransmissionMode( query.value(12).toString() );
631  pVideoMultiplex->setGuardInterval( query.value(13).toString() );
632  pVideoMultiplex->setVisible( query.value(14).toBool() );
633  pVideoMultiplex->setConstellation( query.value(15).toString() );
634  pVideoMultiplex->setHierarchy( query.value(16).toString() );
635  pVideoMultiplex->setHPCodeRate( query.value(17).toString() );
636  pVideoMultiplex->setModulationSystem( query.value(18).toString() );
637  pVideoMultiplex->setRollOff( query.value(19).toString() );
638  pVideoMultiplex->setSIStandard( query.value(20).toString() );
639  pVideoMultiplex->setServiceVersion( query.value(21).toInt() );
640  pVideoMultiplex->setUpdateTimeStamp(
641  MythDate::as_utc(query.value(22).toDateTime()));
642  pVideoMultiplex->setDefaultAuthority( query.value(23).toString() );
643  }
644  }
645 
646  int curPage = 0;
647  int totalPages = 0;
648  if (nCount == 0)
649  totalPages = 1;
650  else
651  totalPages = (int)ceil((float)muxCount / nCount);
652 
653  if (totalPages == 1)
654  curPage = 1;
655  else
656  {
657  curPage = (int)ceil((float)nStartIndex / nCount) + 1;
658  }
659 
660  pVideoMultiplexes->setStartIndex ( nStartIndex );
661  pVideoMultiplexes->setCount ( nCount );
662  pVideoMultiplexes->setCurrentPage ( curPage );
663  pVideoMultiplexes->setTotalPages ( totalPages );
664  pVideoMultiplexes->setTotalAvailable( muxCount );
665  pVideoMultiplexes->setAsOf ( MythDate::current() );
666  pVideoMultiplexes->setVersion ( MYTH_BINARY_VERSION );
667  pVideoMultiplexes->setProtoVer ( MYTH_PROTO_VERSION );
668 
669  return pVideoMultiplexes;
670 }
671 
673 {
675 
676  if (!query.isConnected())
677  throw( QString("Database not open while trying to list "
678  "Video Multiplex."));
679 
680  query.prepare("SELECT sourceid, transportid, networkid, "
681  "frequency, inversion, symbolrate, fec, polarity, "
682  "modulation, bandwidth, lp_code_rate, transmission_mode, "
683  "guard_interval, visible, constellation, hierarchy, hp_code_rate, "
684  "mod_sys, rolloff, sistandard, serviceversion, updatetimestamp, "
685  "default_authority FROM dtv_multiplex WHERE mplexid = :MPLEXID "
686  "ORDER BY mplexid" );
687  query.bindValue(":MPLEXID", nMplexID);
688 
689  if (!query.exec())
690  {
691  MythDB::DBError("MythAPI::GetVideoMultiplex()", query);
692 
693  throw( QString( "Database Error executing query." ));
694  }
695 
696  auto *pVideoMultiplex = new DTC::VideoMultiplex();
697 
698  if (query.next())
699  {
700  pVideoMultiplex->setMplexId( nMplexID );
701  pVideoMultiplex->setSourceId( query.value(0).toInt() );
702  pVideoMultiplex->setTransportId( query.value(1).toInt() );
703  pVideoMultiplex->setNetworkId( query.value(2).toInt() );
704  pVideoMultiplex->setFrequency( query.value(3).toLongLong() );
705  pVideoMultiplex->setInversion( query.value(4).toString() );
706  pVideoMultiplex->setSymbolRate( query.value(5).toLongLong() );
707  pVideoMultiplex->setFEC( query.value(6).toString() );
708  pVideoMultiplex->setPolarity( query.value(7).toString() );
709  pVideoMultiplex->setModulation( query.value(8).toString() );
710  pVideoMultiplex->setBandwidth( query.value(9).toString() );
711  pVideoMultiplex->setLPCodeRate( query.value(10).toString() );
712  pVideoMultiplex->setTransmissionMode( query.value(11).toString() );
713  pVideoMultiplex->setGuardInterval( query.value(12).toString() );
714  pVideoMultiplex->setVisible( query.value(13).toBool() );
715  pVideoMultiplex->setConstellation( query.value(14).toString() );
716  pVideoMultiplex->setHierarchy( query.value(15).toString() );
717  pVideoMultiplex->setHPCodeRate( query.value(16).toString() );
718  pVideoMultiplex->setModulationSystem( query.value(17).toString() );
719  pVideoMultiplex->setRollOff( query.value(18).toString() );
720  pVideoMultiplex->setSIStandard( query.value(19).toString() );
721  pVideoMultiplex->setServiceVersion( query.value(20).toInt() );
722  pVideoMultiplex->setUpdateTimeStamp(
723  MythDate::as_utc(query.value(21).toDateTime()));
724  pVideoMultiplex->setDefaultAuthority( query.value(22).toString() );
725  }
726 
727  return pVideoMultiplex;
728 }
729 
731 //
733 
735 {
737 
738  if (!query.isConnected())
739  throw( QString("Database not open while trying to get source name."));
740 
741  query.prepare("SELECT name FROM videosource WHERE sourceid = :SOURCEID ");
742  query.bindValue(":SOURCEID", SourceID);
743 
744  if (!query.exec())
745  {
746  MythDB::DBError("MythAPI::GetXMLTVIdList()", query);
747 
748  throw( QString( "Database Error executing query." ));
749  }
750 
751  QStringList idList;
752 
753  if (query.next())
754  {
755  QString sourceName = query.value(0).toString();
756 
757  QString xmltvFile = GetConfDir() + '/' + sourceName + ".xmltv";
758 
759  if (QFile::exists(xmltvFile))
760  {
761  QFile file(xmltvFile);
762  if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
763  return idList;
764 
765  while (!file.atEnd())
766  {
767  QByteArray line = file.readLine();
768 
769  if (line.startsWith("channel="))
770  {
771  QString id = line.mid(8, -1).trimmed();
772  idList.append(id);
773  }
774  }
775 
776  idList.sort();
777  }
778  }
779  else
780  throw(QString("SourceID (%1) not found").arg(SourceID));
781 
782  return idList;
783 }
ChannelInfo
Definition: channelinfo.h:34
serviceUtil.h
MSqlBindings
QMap< QString, QVariant > MSqlBindings
typedef for a map of string -> string bindings for generic queries.
Definition: mythdbcon.h:98
Channel::FetchChannelsFromSource
int FetchChannelsFromSource(uint SourceId, uint CardId, bool WaitForFinish) override
Definition: channel.cpp:545
MSqlQuery::next
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:783
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:126
DTC::VideoSourceList
Definition: videoSourceList.h:16
channel
QDomElement channel
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:498
MSqlQuery::size
int size(void) const
Definition: mythdbcon.h:203
SourceUtil::DeleteSource
static bool DeleteSource(uint sourceid)
Definition: sourceutil.cpp:531
Channel::RemoveDBChannel
bool RemoveDBChannel(uint ChannelID) override
Definition: channel.cpp:267
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:135
UseEIT
Definition: videosource.cpp:559
kChannelNeverVisible
@ kChannelNeverVisible
Definition: channelinfo.h:27
channel.h
ChannelUtil::DeleteChannel
static bool DeleteChannel(uint channel_id)
Definition: channelutil.cpp:1766
Channel::GetVideoMultiplexList
DTC::VideoMultiplexList * GetVideoMultiplexList(uint SourceID, uint StartIndex, uint Count) override
Definition: channel.cpp:574
DTC::VideoMultiplex
Definition: videoMultiplex.h:16
ChannelUtil::kChanGroupByChanid
@ kChanGroupByChanid
Definition: channelutil.h:206
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:198
arg
arg(title).arg(filename).arg(doDelete))
mythdbcon.h
Channel::GetXMLTVIdList
QStringList GetXMLTVIdList(uint SourceID) override
Definition: channel.cpp:734
FillChannelInfo
bool FillChannelInfo(DTC::ChannelInfo *pChannel, uint nChanID, bool bDetails)
Definition: serviceUtil.cpp:168
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:603
MythDate::Format
Format
Definition: mythdate.h:13
Channel::GetVideoMultiplex
DTC::VideoMultiplex * GetVideoMultiplex(uint MplexID) override
Definition: channel.cpp:672
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
SourceID
Definition: videosource.cpp:2799
ChannelUtil::kChanOrderByName
@ kChanOrderByName
Definition: channelutil.h:199
Channel::GetDDLineupList
DTC::LineupList * GetDDLineupList(const QString &, const QString &, const QString &) override
Definition: channel.cpp:533
build_compdb.file
file
Definition: build_compdb.py:55
mythdirs.h
DTC::ChannelInfoList
Definition: channelInfoList.h:15
kChannelAlwaysVisible
@ kChannelAlwaysVisible
Definition: channelinfo.h:24
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:1482
Visible
Definition: channelsettings.cpp:392
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:21
SourceUtil::IsSourceIDValid
static bool IsSourceIDValid(uint sourceid)
Definition: sourceutil.cpp:387
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
mythdate.h
sourceutil.h
SourceUtil::UpdateChannelsFromListings
static bool UpdateChannelsFromListings(uint sourceid, const QString &inputtype=QString(), bool wait=false)
Definition: sourceutil.cpp:403
ServiceID
Definition: channelsettings.cpp:313
GetConfDir
QString GetConfDir(void)
Definition: mythdirs.cpp:224
channelVisibleTypeFromString
ChannelVisibleType channelVisibleTypeFromString(const QString &type)
Definition: channelinfo.cpp:531
CardUtil::IsEncoder
static bool IsEncoder(const QString &rawtype)
Definition: cardutil.h:130
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:15
DTC::LineupList
Definition: lineup.h:67
MythDB::DBError
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:179
Channel::GetVideoSource
DTC::VideoSource * GetVideoSource(uint SourceID) override
Definition: channel.cpp:335
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:803
ChannelVisibleType
ChannelVisibleType
Definition: channelinfo.h:23
ChannelInfoList
vector< ChannelInfo > ChannelInfoList
Definition: channelinfo.h:133
MSqlQuery::isConnected
bool isConnected(void) const
Only updated once during object creation.
Definition: mythdbcon.h:135
uint
unsigned int uint
Definition: compat.h:140
channelutil.h
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:1562
CardUtil::GetRawInputType
static QString GetRawInputType(uint inputid)
Definition: cardutil.h:282
HAS_PARAM
#define HAS_PARAM(p)
Definition: serviceUtil.h:54
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
kChannelVisible
@ kChannelVisible
Definition: channelinfo.h:25
mythcorecontext.h
cardutil.h
MSqlQuery::bindValue
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:864
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) override
Definition: channel.cpp:387
Channel::RemoveVideoSource
bool RemoveVideoSource(uint SourceID) override
Definition: channel.cpp:522
Icon
Definition: channelsettings.cpp:209
DTC::VideoMultiplexList
Definition: videoMultiplexList.h:16
DTC::ChannelInfo
Definition: programAndChannel.h:31
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) override
Definition: channel.cpp:498
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)
Definition: sourceutil.cpp:482
CardUtil::IsUnscanable
static bool IsUnscanable(const QString &rawtype)
Definition: cardutil.h:153
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
query
MSqlQuery query(MSqlQuery::InitCon())
Channel::GetChannelInfo
DTC::ChannelInfo * GetChannelInfo(uint ChanID) override
Definition: channel.cpp:127
ChannelUtil::kChanOrderByChanNum
@ kChanOrderByChanNum
Definition: channelutil.h:198
ChannelUtil::kChanGroupByCallsign
@ kChanGroupByCallsign
Definition: channelutil.h:205
kChannelNotVisible
@ kChannelNotVisible
Definition: channelinfo.h:26
MSqlQuery::prepare
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:808
ADD_SQL
#define ADD_SQL(settings_var, bindvar, col, api_param, val)
Definition: serviceUtil.h:49