MythTV  master
channelimporter.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 /*
3  * Copyright (C) Daniel Kristjansson 2007
4  *
5  * This file is licensed under GPL v2 or (at your option) any later version.
6  *
7  */
8 
9 #ifndef CHANNEL_IMPORTER_H
10 #define CHANNEL_IMPORTER_H
11 
12 // C++ headers
13 #include <cstring>
14 
15 // Qt headers
16 #include <QMap>
17 #include <QObject>
18 #include <QString>
19 #include <QCoreApplication>
20 
21 // MythTV headers
22 #include "libmythtv/mythtvexp.h"
24 
25 #include "scaninfo.h"
26 #include "channelscantypes.h"
27 #include "channelscanner_web.h"
28 
29 enum OkCancelType : std::int8_t {
31  kOCTCancel = +0,
32  kOCTOk = +1,
33  kOCTOkAll = +2,
34 };
35 
36 using ChanStats = std::array<uint,3>;
37 
39 {
40  public:
41  ChannelImporterBasicStats() = default;
42 
43  // totals
49 
50  // per channel counts
51  QMap<uint,uint> m_progNumCnt;
52  QMap<uint,uint> m_atscNumCnt;
53  QMap<uint,uint> m_atscMinCnt;
54  QMap<uint,uint> m_atscMajCnt;
55  QMap<QString,uint> m_chanNumCnt;
56 };
57 
59 {
60  public:
62 
69 };
70 
71 class MTV_PUBLIC ChannelImporter : public QObject
72 {
73  Q_OBJECT
74 
75  public:
76  ChannelImporter(bool gui, bool interactive,
77  bool _delete, bool insert, bool save,
78  bool fta_only, bool lcn_only, bool complete_only,
79  bool full_channel_search,
80  bool remove_duplicates,
81  ServiceRequirements service_requirements,
82  bool success = false);
83 
84  void Process(const ScanDTVTransportList &_transports, int sourceid = -1);
85 
86  protected:
87  enum DeleteAction : std::uint8_t
88  {
93  };
94  enum InsertAction : std::uint8_t
95  {
99  };
100  enum UpdateAction : std::uint8_t
101  {
105  };
106 
107  enum ChannelType : std::uint8_t
108  {
109  kChannelTypeFirst = 0,
110 
111  kChannelTypeNonConflictingFirst = kChannelTypeFirst,
112  kATSCNonConflicting = kChannelTypeFirst,
113  kDVBNonConflicting = 1,
114  kSCTENonConflicting = 2,
115  kMPEGNonConflicting = 3,
116  kNTSCNonConflicting = 4,
117  kChannelTypeNonConflictingLast = kNTSCNonConflicting,
118 
119  kChannelTypeConflictingFirst = 5,
120  kATSCConflicting = kChannelTypeConflictingFirst,
121  kDVBConflicting = 6,
122  kSCTEConflicting = 7,
123  kMPEGConflicting = 8,
124  kNTSCConflicting = 9,
125  kChannelTypeConflictingLast = kNTSCConflicting,
126  kChannelTypeLast = kChannelTypeConflictingLast,
127  };
128 
129  static QString toString(ChannelType type);
130 
131  static void MergeSameFrequency(ScanDTVTransportList &transports);
132  static void RemoveDuplicates(ScanDTVTransportList &transports, ScanDTVTransportList &duplicates);
133  void FilterServices(ScanDTVTransportList &transports) const;
134  static void FilterRelocatedServices(ScanDTVTransportList &transports);
135  void ChannelNumbers(ScanDTVTransportList &transports) const;
136 
137  ScanDTVTransportList GetDBTransports(
138  uint sourceid, ScanDTVTransportList &transports) const;
139 
140  uint DeleteChannels(ScanDTVTransportList &transports);
141  uint DeleteUnusedTransports(uint sourceid);
142 
143  void InsertChannels(const ScanDTVTransportList &transports,
145 
146  ScanDTVTransportList InsertChannels(
147  const ScanDTVTransportList &transports,
149  InsertAction action,
150  ChannelType type,
151  ScanDTVTransportList &inserted,
152  ScanDTVTransportList &skipped);
153 
154  ScanDTVTransportList UpdateChannels(
155  const ScanDTVTransportList &transports,
157  UpdateAction action,
158  ChannelType type,
159  ScanDTVTransportList &updated,
160  ScanDTVTransportList &skipped) const;
161 
163  DeleteAction QueryUserDelete(const QString &msg);
164 
166  InsertAction QueryUserInsert(const QString &msg);
167 
169  UpdateAction QueryUserUpdate(const QString &msg);
170 
172  OkCancelType QueryUserResolve(
173  const ScanDTVTransport &transport,
174  ChannelInsertInfo &chan);
175 
177  OkCancelType QueryUserInsert(
178  const ScanDTVTransport &transport,
179  ChannelInsertInfo &chan);
180 
181  static QString ComputeSuggestedChannelNum(
182  const ChannelInsertInfo &chan);
183 
184  OkCancelType ShowManualChannelPopup(
185  const QString& title,
186  const QString& message, QString &text);
187 
188  OkCancelType ShowResolveChannelPopup(
189  const QString& title,
190  const QString& message, QString &text);
191 
192  static void FixUpOpenCable(ScanDTVTransportList &transports);
193 
194  static ChannelImporterBasicStats CollectStats(
195  const ScanDTVTransportList &transports);
196 
197  static ChannelImporterUniquenessStats CollectUniquenessStats(
198  const ScanDTVTransportList &transports,
200 
201  static QString FormatChannels(
202  const ScanDTVTransportList &transports,
203  const ChannelImporterBasicStats *info = nullptr);
204 
205  static QString FormatChannel(
206  const ScanDTVTransport &transport,
207  const ChannelInsertInfo &chan,
208  const ChannelImporterBasicStats *info = nullptr);
209 
210  static QString SimpleFormatChannel(
211  const ScanDTVTransport &transport,
212  const ChannelInsertInfo &chan);
213 
214  static QString FormatTransport(
215  const ScanDTVTransport &transport);
216 
217  static QString FormatTransports(
218  const ScanDTVTransportList &transports_in);
219 
220  static QString GetSummary(
222  const ChannelImporterUniquenessStats &stats);
223 
224  static bool IsType(
226  const ChannelInsertInfo &chan, ChannelType type);
227 
228  static void CountChannels(
229  const ScanDTVTransportList &transports,
231  ChannelType type, uint &new_chan, uint &old_chan);
232 
233  static int SimpleCountChannels(
234  const ScanDTVTransportList &transports);
235 
236  static bool CheckChannelNumber(
237  const QString &num,
238  const ChannelInsertInfo &chan);
239 
240  static void AddChanToCopy(
241  ScanDTVTransport &transport_copy,
242  const ScanDTVTransport &transport,
243  const ChannelInsertInfo &chan);
244 
245  private:
246  bool m_useGui;
248  bool m_useWeb {false};
251  bool m_doSave;
252  bool m_doLcn {true}; // Use Logical Channel Numbers
253  bool m_doScn {true}; // Use HD Simulcast logical channel numbers
254  bool m_ftaOnly {true}; // Only FreeToAir (non-encrypted) channels desired post scan?
255  bool m_lcnOnly {false}; // Only services with logical channel numbers desired post scan?
256  bool m_completeOnly {true}; // Only services with complete scandata desired post scan?
257  bool m_keepChannelNumbers {true}; // Keep existing channel numbers on channel update
258  bool m_fullChannelSearch {false}; // Full search for old channels across transports in database
259  bool m_removeDuplicates {false}; // Remove duplicate transports and channels in scan
260  bool m_success {false}; // To pass information IPTV channel scan succeeded
261  int m_lcnOffset {0}; // Read from database table videosource
262  int m_functorRetval {0};
263  ChannelScannerWeb * m_pWeb {nullptr};
264 
265  ServiceRequirements m_serviceRequirements; // Services desired post scan
266  QEventLoop m_eventLoop;
267 };
268 
269 #endif // CHANNEL_IMPORTER_H
kOCTCancel
@ kOCTCancel
Definition: channelimporter.h:31
ChannelImporterBasicStats::m_chanNumCnt
QMap< QString, uint > m_chanNumCnt
Definition: channelimporter.h:55
MythDate::toString
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
Definition: mythdate.cpp:93
RemoveDuplicates
Definition: channelscanmiscsettings.h:174
ChannelImporter::m_isInteractive
bool m_isInteractive
Definition: channelimporter.h:247
OkCancelType
OkCancelType
Definition: channelimporter.h:29
mythtvexp.h
kOCTOkAll
@ kOCTOkAll
Definition: channelimporter.h:33
ChannelImporter::m_doInsert
bool m_doInsert
Definition: channelimporter.h:250
channelscanner_web.h
ChannelImporterUniquenessStats::m_uniqueProgNum
uint m_uniqueProgNum
Definition: channelimporter.h:63
ChannelImporter::kDeleteInvisibleAll
@ kDeleteInvisibleAll
Definition: channelimporter.h:92
ChannelImporterBasicStats::m_atscChannels
ChanStats m_atscChannels
Definition: channelimporter.h:44
ChannelImporter::m_doDelete
bool m_doDelete
Definition: channelimporter.h:249
ChannelImporterBasicStats::m_atscNumCnt
QMap< uint, uint > m_atscNumCnt
Definition: channelimporter.h:52
ChannelImporter::m_serviceRequirements
ServiceRequirements m_serviceRequirements
Definition: channelimporter.h:265
ChannelInsertInfo
Definition: channelinfo.h:133
ChannelImporter::m_useGui
bool m_useGui
Definition: channelimporter.h:246
ChanStats
std::array< uint, 3 > ChanStats
Definition: channelimporter.h:36
ChannelImporter::ChannelType
ChannelType
Definition: channelimporter.h:107
channelscantypes.h
ChannelImporterBasicStats::m_atscMajCnt
QMap< uint, uint > m_atscMajCnt
Definition: channelimporter.h:54
ChannelImporter::kDeleteIgnoreAll
@ kDeleteIgnoreAll
Definition: channelimporter.h:91
ChannelImporter::UpdateAction
UpdateAction
Definition: channelimporter.h:100
kOCTOk
@ kOCTOk
Definition: channelimporter.h:32
ChannelImporter::kInsertManual
@ kInsertManual
Definition: channelimporter.h:97
ChannelImporter::kUpdateAll
@ kUpdateAll
Definition: channelimporter.h:102
ServiceRequirements
ServiceRequirements
Definition: channelscantypes.h:4
ChannelImporter::kDeleteManual
@ kDeleteManual
Definition: channelimporter.h:90
ChannelImporter::kInsertIgnoreAll
@ kInsertIgnoreAll
Definition: channelimporter.h:98
scaninfo.h
ChannelImporterBasicStats::ChannelImporterBasicStats
ChannelImporterBasicStats()=default
ChannelImporter::m_eventLoop
QEventLoop m_eventLoop
Definition: channelimporter.h:266
ScanDTVTransportList
std::vector< ScanDTVTransport > ScanDTVTransportList
Definition: dtvmultiplex.h:143
kOCTCancelAll
@ kOCTCancelAll
Definition: channelimporter.h:30
ChannelImporter::DeleteAction
DeleteAction
Definition: channelimporter.h:87
ChannelScannerWeb
Definition: channelscanner_web.h:46
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
ChannelImporterUniquenessStats::m_uniqueChanNum
uint m_uniqueChanNum
Definition: channelimporter.h:66
ChannelImporterBasicStats::m_ntscChannels
ChanStats m_ntscChannels
Definition: channelimporter.h:48
ChannelImporterBasicStats::m_progNumCnt
QMap< uint, uint > m_progNumCnt
Definition: channelimporter.h:51
ChannelImporter
Definition: channelimporter.h:71
ChannelImporterUniquenessStats::m_uniqueTotal
uint m_uniqueTotal
Definition: channelimporter.h:67
ChannelImporterUniquenessStats::m_uniqueAtscMin
uint m_uniqueAtscMin
Definition: channelimporter.h:65
ChannelImporterUniquenessStats::m_maxAtscMajCnt
uint m_maxAtscMajCnt
Definition: channelimporter.h:68
build_compdb.action
action
Definition: build_compdb.py:9
ChannelImporter::kUpdateManual
@ kUpdateManual
Definition: channelimporter.h:103
ChannelImporter::kUpdateIgnoreAll
@ kUpdateIgnoreAll
Definition: channelimporter.h:104
ChannelImporterBasicStats
Definition: channelimporter.h:38
ChannelImporter::InsertAction
InsertAction
Definition: channelimporter.h:94
azlyrics.info
dictionary info
Definition: azlyrics.py:7
ChannelImporterBasicStats::m_scteChannels
ChanStats m_scteChannels
Definition: channelimporter.h:46
ChannelImporter::kInsertAll
@ kInsertAll
Definition: channelimporter.h:96
ChannelImporterUniquenessStats::m_uniqueAtscNum
uint m_uniqueAtscNum
Definition: channelimporter.h:64
ChannelImporterBasicStats::m_dvbChannels
ChanStats m_dvbChannels
Definition: channelimporter.h:45
ChannelImporterBasicStats::m_mpegChannels
ChanStats m_mpegChannels
Definition: channelimporter.h:47
ChannelImporter::kDeleteAll
@ kDeleteAll
Definition: channelimporter.h:89
mythmainwindow.h
ChannelImporterUniquenessStats::ChannelImporterUniquenessStats
ChannelImporterUniquenessStats()=default
ChannelImporter::m_doSave
bool m_doSave
Definition: channelimporter.h:251
ChannelImporterBasicStats::m_atscMinCnt
QMap< uint, uint > m_atscMinCnt
Definition: channelimporter.h:53
ChannelImporterUniquenessStats
Definition: channelimporter.h:58
uint
unsigned int uint
Definition: freesurround.h:24
ScanDTVTransport
Definition: dtvmultiplex.h:115