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 
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:
88  {
93  };
95  {
99  };
101  {
105  };
106 
108  {
109  kChannelTypeFirst = 0,
110 
111  kChannelTypeNonConflictingFirst = kChannelTypeFirst,
112  kATSCNonConflicting = kChannelTypeFirst,
117  kChannelTypeNonConflictingLast = kNTSCNonConflicting,
118 
120  kATSCConflicting = kChannelTypeConflictingFirst,
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 
136  ScanDTVTransportList GetDBTransports(
137  uint sourceid, ScanDTVTransportList &transports) const;
138 
139  uint DeleteChannels(ScanDTVTransportList &transports);
140  uint DeleteUnusedTransports(uint sourceid);
141 
142  void InsertChannels(const ScanDTVTransportList &transports,
143  const ChannelImporterBasicStats &info);
144 
145  ScanDTVTransportList InsertChannels(
146  const ScanDTVTransportList &transports,
147  const ChannelImporterBasicStats &info,
148  InsertAction action,
149  ChannelType type,
150  ScanDTVTransportList &inserted,
151  ScanDTVTransportList &skipped);
152 
153  ScanDTVTransportList UpdateChannels(
154  const ScanDTVTransportList &transports,
155  const ChannelImporterBasicStats &info,
156  UpdateAction action,
157  ChannelType type,
158  ScanDTVTransportList &updated,
159  ScanDTVTransportList &skipped) const;
160 
162  DeleteAction QueryUserDelete(const QString &msg);
163 
165  InsertAction QueryUserInsert(const QString &msg);
166 
168  UpdateAction QueryUserUpdate(const QString &msg);
169 
171  OkCancelType QueryUserResolve(
172  const ScanDTVTransport &transport,
173  ChannelInsertInfo &chan);
174 
176  OkCancelType QueryUserInsert(
177  const ScanDTVTransport &transport,
178  ChannelInsertInfo &chan);
179 
180  static QString ComputeSuggestedChannelNum(
181  const ChannelInsertInfo &chan);
182 
183  OkCancelType ShowManualChannelPopup(
184  const QString& title,
185  const QString& message, QString &text);
186 
187  OkCancelType ShowResolveChannelPopup(
188  const QString& title,
189  const QString& message, QString &text);
190 
191  static void FixUpOpenCable(ScanDTVTransportList &transports);
192 
193  static ChannelImporterBasicStats CollectStats(
194  const ScanDTVTransportList &transports);
195 
196  static ChannelImporterUniquenessStats CollectUniquenessStats(
197  const ScanDTVTransportList &transports,
198  const ChannelImporterBasicStats &info);
199 
200  static QString FormatChannels(
201  const ScanDTVTransportList &transports,
202  const ChannelImporterBasicStats *info = nullptr);
203 
204  static QString FormatChannel(
205  const ScanDTVTransport &transport,
206  const ChannelInsertInfo &chan,
207  const ChannelImporterBasicStats *info = nullptr);
208 
209  static QString SimpleFormatChannel(
210  const ScanDTVTransport &transport,
211  const ChannelInsertInfo &chan);
212 
213  static QString FormatTransport(
214  const ScanDTVTransport &transport);
215 
216  static QString FormatTransports(
217  const ScanDTVTransportList &transports_in);
218 
219  static QString GetSummary(
220  const ChannelImporterBasicStats &info,
221  const ChannelImporterUniquenessStats &stats);
222 
223  static bool IsType(
224  const ChannelImporterBasicStats &info,
225  const ChannelInsertInfo &chan, ChannelType type);
226 
227  static void CountChannels(
228  const ScanDTVTransportList &transports,
229  const ChannelImporterBasicStats &info,
230  ChannelType type, uint &new_chan, uint &old_chan);
231 
232  static int SimpleCountChannels(
233  const ScanDTVTransportList &transports);
234 
235  static bool CheckChannelNumber(
236  const QString &num,
237  const ChannelInsertInfo &chan);
238 
239  static void AddChanToCopy(
240  ScanDTVTransport &transport_copy,
241  const ScanDTVTransport &transport,
242  const ChannelInsertInfo &chan);
243 
244  private:
245  bool m_useGui;
247  bool m_useWeb {false};
250  bool m_doSave;
251  bool m_ftaOnly {true}; // Only FreeToAir (non-encrypted) channels desired post scan?
252  bool m_lcnOnly {false}; // Only services with logical channel numbers desired post scan?
253  bool m_completeOnly {true}; // Only services with complete scandata desired post scan?
254  bool m_keepChannelNumbers {true}; // Keep existing channel numbers on channel update
255  bool m_fullChannelSearch {false}; // Full search for old channels across transports in database
256  bool m_removeDuplicates {false}; // Remove duplicate transports and channels in scan
257  bool m_success {false}; // To pass information IPTV channel scan succeeded
258  int m_functorRetval {0};
259  ChannelScannerWeb * m_pWeb {nullptr};
260 
261  ServiceRequirements m_serviceRequirements; // Services desired post scan
262  QEventLoop m_eventLoop;
263 };
264 
265 #endif // CHANNEL_IMPORTER_H
ChannelImporter::kSCTEConflicting
@ kSCTEConflicting
Definition: channelimporter.h:122
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:84
RemoveDuplicates
Definition: channelscanmiscsettings.h:174
OkCancelType
OkCancelType
Definition: channelimporter.h:29
ChannelImporter::m_isInteractive
bool m_isInteractive
Definition: channelimporter.h:246
ChannelImporter::kUpdateIgnoreAll
@ kUpdateIgnoreAll
Definition: channelimporter.h:104
mythtvexp.h
kOCTCancel
@ kOCTCancel
Definition: channelimporter.h:31
ChannelImporter::m_doInsert
bool m_doInsert
Definition: channelimporter.h:249
ChannelImporter::kDVBConflicting
@ kDVBConflicting
Definition: channelimporter.h:121
ChannelImporter::kNTSCNonConflicting
@ kNTSCNonConflicting
Definition: channelimporter.h:116
channelscanner_web.h
ChannelImporter::kUpdateManual
@ kUpdateManual
Definition: channelimporter.h:103
ChannelImporter::kChannelTypeConflictingFirst
@ kChannelTypeConflictingFirst
Definition: channelimporter.h:119
ChannelImporterUniquenessStats::m_uniqueProgNum
uint m_uniqueProgNum
Definition: channelimporter.h:63
ChannelImporter::UpdateAction
UpdateAction
Definition: channelimporter.h:100
ChannelImporterBasicStats::m_atscChannels
ChanStats m_atscChannels
Definition: channelimporter.h:44
ChannelImporter::m_doDelete
bool m_doDelete
Definition: channelimporter.h:248
ChannelImporterBasicStats::m_atscNumCnt
QMap< uint, uint > m_atscNumCnt
Definition: channelimporter.h:52
ChannelImporter::m_serviceRequirements
ServiceRequirements m_serviceRequirements
Definition: channelimporter.h:261
kOCTOk
@ kOCTOk
Definition: channelimporter.h:32
ChannelInsertInfo
Definition: channelinfo.h:133
ChannelImporter::DeleteAction
DeleteAction
Definition: channelimporter.h:87
ChannelImporter::m_useGui
bool m_useGui
Definition: channelimporter.h:245
ChanStats
std::array< uint, 3 > ChanStats
Definition: channelimporter.h:36
ChannelImporter::kMPEGConflicting
@ kMPEGConflicting
Definition: channelimporter.h:123
channelscantypes.h
ChannelImporterBasicStats::m_atscMajCnt
QMap< uint, uint > m_atscMajCnt
Definition: channelimporter.h:54
ChannelImporter::kDeleteAll
@ kDeleteAll
Definition: channelimporter.h:89
ChannelImporter::kDVBNonConflicting
@ kDVBNonConflicting
Definition: channelimporter.h:113
ChannelImporter::kSCTENonConflicting
@ kSCTENonConflicting
Definition: channelimporter.h:114
scaninfo.h
ChannelImporterBasicStats::ChannelImporterBasicStats
ChannelImporterBasicStats()=default
ChannelImporter::kInsertManual
@ kInsertManual
Definition: channelimporter.h:97
uint
unsigned int uint
Definition: compat.h:81
ChannelImporter::m_eventLoop
QEventLoop m_eventLoop
Definition: channelimporter.h:262
ScanDTVTransportList
std::vector< ScanDTVTransport > ScanDTVTransportList
Definition: dtvmultiplex.h:143
ChannelScannerWeb
Definition: channelscanner_web.h:46
ChannelImporter::kDeleteManual
@ kDeleteManual
Definition: channelimporter.h:90
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
kOCTCancelAll
@ kOCTCancelAll
Definition: channelimporter.h:30
ChannelImporter::kMPEGNonConflicting
@ kMPEGNonConflicting
Definition: channelimporter.h:115
ChannelImporter::kDeleteIgnoreAll
@ kDeleteIgnoreAll
Definition: channelimporter.h:91
ChannelImporter::kInsertAll
@ kInsertAll
Definition: channelimporter.h:96
ChannelImporter
Definition: channelimporter.h:71
ChannelImporterUniquenessStats::m_uniqueTotal
uint m_uniqueTotal
Definition: channelimporter.h:67
ChannelImporter::kUpdateAll
@ kUpdateAll
Definition: channelimporter.h:102
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::InsertAction
InsertAction
Definition: channelimporter.h:94
ChannelImporterBasicStats
Definition: channelimporter.h:38
ChannelImporterBasicStats::m_scteChannels
ChanStats m_scteChannels
Definition: channelimporter.h:46
ChannelImporterUniquenessStats::m_uniqueAtscNum
uint m_uniqueAtscNum
Definition: channelimporter.h:64
ServiceRequirements
ServiceRequirements
Definition: channelscantypes.h:4
ChannelImporterBasicStats::m_dvbChannels
ChanStats m_dvbChannels
Definition: channelimporter.h:45
ChannelImporterBasicStats::m_mpegChannels
ChanStats m_mpegChannels
Definition: channelimporter.h:47
mythmainwindow.h
ChannelImporterUniquenessStats::ChannelImporterUniquenessStats
ChannelImporterUniquenessStats()=default
ChannelImporter::kInsertIgnoreAll
@ kInsertIgnoreAll
Definition: channelimporter.h:98
ChannelImporter::m_doSave
bool m_doSave
Definition: channelimporter.h:250
ChannelImporterBasicStats::m_atscMinCnt
QMap< uint, uint > m_atscMinCnt
Definition: channelimporter.h:53
ChannelImporter::ChannelType
ChannelType
Definition: channelimporter.h:107
ChannelImporterUniquenessStats
Definition: channelimporter.h:58
ChannelImporter::kNTSCConflicting
@ kNTSCConflicting
Definition: channelimporter.h:124
ScanDTVTransport
Definition: dtvmultiplex.h:115
ChannelImporter::kDeleteInvisibleAll
@ kDeleteInvisibleAll
Definition: channelimporter.h:92
kOCTOkAll
@ kOCTOkAll
Definition: channelimporter.h:33