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 
30  kOCTCancel = +0,
31  kOCTOk = +1,
32  kOCTOkAll = +2,
33 };
34 
35 using ChanStats = std::array<uint,3>;
36 
38 {
39  public:
40  ChannelImporterBasicStats() = default;
41 
42  // totals
48 
49  // per channel counts
50  QMap<uint,uint> m_progNumCnt;
51  QMap<uint,uint> m_atscNumCnt;
52  QMap<uint,uint> m_atscMinCnt;
53  QMap<uint,uint> m_atscMajCnt;
54  QMap<QString,uint> m_chanNumCnt;
55 };
56 
58 {
59  public:
61 
68 };
69 
70 class MTV_PUBLIC ChannelImporter : public QObject
71 {
72  Q_OBJECT
73 
74  public:
75  ChannelImporter(bool gui, bool interactive,
76  bool _delete, bool insert, bool save,
77  bool fta_only, bool lcn_only, bool complete_only,
78  bool full_channel_search,
79  bool remove_duplicates,
80  ServiceRequirements service_requirements,
81  bool success = false) :
82  m_useGui(gui),
83  m_isInteractive(interactive),
84  m_doDelete(_delete),
85  m_doInsert(insert),
86  m_doSave(save),
87  m_ftaOnly(fta_only),
88  m_lcnOnly(lcn_only),
89  m_completeOnly(complete_only),
90  m_fullChannelSearch(full_channel_search),
91  m_removeDuplicates(remove_duplicates),
92  m_success(success),
93  m_serviceRequirements(service_requirements) { }
94 
95  void Process(const ScanDTVTransportList &_transports, int sourceid = -1);
96 
97  protected:
99  {
104  };
106  {
110  };
112  {
116  };
117 
119  {
120  kChannelTypeFirst = 0,
121 
122  kChannelTypeNonConflictingFirst = kChannelTypeFirst,
123  kATSCNonConflicting = kChannelTypeFirst,
128  kChannelTypeNonConflictingLast = kNTSCNonConflicting,
129 
131  kATSCConflicting = kChannelTypeConflictingFirst,
136  kChannelTypeConflictingLast = kNTSCConflicting,
137  kChannelTypeLast = kChannelTypeConflictingLast,
138  };
139 
140  static QString toString(ChannelType type);
141 
142  static void MergeSameFrequency(ScanDTVTransportList &transports);
143  static void RemoveDuplicates(ScanDTVTransportList &transports, ScanDTVTransportList &duplicates);
144  void FilterServices(ScanDTVTransportList &transports) const;
145  static void FilterRelocatedServices(ScanDTVTransportList &transports);
146 
147  ScanDTVTransportList GetDBTransports(
148  uint sourceid, ScanDTVTransportList &transports) const;
149 
150  uint DeleteChannels(ScanDTVTransportList &transports);
151  uint DeleteUnusedTransports(uint sourceid);
152 
153  void InsertChannels(const ScanDTVTransportList &transports,
154  const ChannelImporterBasicStats &info);
155 
156  ScanDTVTransportList InsertChannels(
157  const ScanDTVTransportList &transports,
158  const ChannelImporterBasicStats &info,
159  InsertAction action,
160  ChannelType type,
161  ScanDTVTransportList &inserted,
162  ScanDTVTransportList &skipped);
163 
164  ScanDTVTransportList UpdateChannels(
165  const ScanDTVTransportList &transports,
166  const ChannelImporterBasicStats &info,
167  UpdateAction action,
168  ChannelType type,
169  ScanDTVTransportList &updated,
170  ScanDTVTransportList &skipped) const;
171 
173  DeleteAction QueryUserDelete(const QString &msg);
174 
176  InsertAction QueryUserInsert(const QString &msg);
177 
179  UpdateAction QueryUserUpdate(const QString &msg);
180 
182  OkCancelType QueryUserResolve(
183  const ScanDTVTransport &transport,
184  ChannelInsertInfo &chan);
185 
187  OkCancelType QueryUserInsert(
188  const ScanDTVTransport &transport,
189  ChannelInsertInfo &chan);
190 
191  static QString ComputeSuggestedChannelNum(
192  const ChannelInsertInfo &chan);
193 
194  OkCancelType ShowManualChannelPopup(
195  MythMainWindow *parent, const QString& title,
196  const QString& message, QString &text);
197 
198  OkCancelType ShowResolveChannelPopup(
199  MythMainWindow *parent, const QString& title,
200  const QString& message, QString &text);
201 
202  static void FixUpOpenCable(ScanDTVTransportList &transports);
203 
204  static ChannelImporterBasicStats CollectStats(
205  const ScanDTVTransportList &transports);
206 
207  static ChannelImporterUniquenessStats CollectUniquenessStats(
208  const ScanDTVTransportList &transports,
209  const ChannelImporterBasicStats &info);
210 
211  static QString FormatChannels(
212  const ScanDTVTransportList &transports,
213  const ChannelImporterBasicStats *info = nullptr);
214 
215  static QString FormatChannel(
216  const ScanDTVTransport &transport,
217  const ChannelInsertInfo &chan,
218  const ChannelImporterBasicStats *info = nullptr);
219 
220  static QString SimpleFormatChannel(
221  const ScanDTVTransport &transport,
222  const ChannelInsertInfo &chan);
223 
224  static QString FormatTransport(
225  const ScanDTVTransport &transport);
226 
227  static QString FormatTransports(
228  const ScanDTVTransportList &transports_in);
229 
230  static QString GetSummary(
231  const ChannelImporterBasicStats &info,
232  const ChannelImporterUniquenessStats &stats);
233 
234  static bool IsType(
235  const ChannelImporterBasicStats &info,
236  const ChannelInsertInfo &chan, ChannelType type);
237 
238  static void CountChannels(
239  const ScanDTVTransportList &transports,
240  const ChannelImporterBasicStats &info,
241  ChannelType type, uint &new_chan, uint &old_chan);
242 
243  static int SimpleCountChannels(
244  const ScanDTVTransportList &transports);
245 
246  static bool CheckChannelNumber(
247  const QString &num,
248  const ChannelInsertInfo &chan);
249 
250  static void AddChanToCopy(
251  ScanDTVTransport &transport_copy,
252  const ScanDTVTransport &transport,
253  const ChannelInsertInfo &chan);
254 
255  private:
256  bool m_useGui;
260  bool m_doSave;
261  bool m_ftaOnly {true}; // Only FreeToAir (non-encrypted) channels desired post scan?
262  bool m_lcnOnly {false}; // Only services with logical channel numbers desired post scan?
263  bool m_completeOnly {true}; // Only services with complete scandata desired post scan?
264  bool m_keepChannelNumbers {true}; // Keep existing channel numbers on channel update
265  bool m_fullChannelSearch {false}; // Full search for old channels across transports in database
266  bool m_removeDuplicates {false}; // Remove duplicate transports and channels in scan
267  bool m_success {false}; // To pass information IPTV channel scan succeeded
268  int m_functorRetval {0};
269 
270  ServiceRequirements m_serviceRequirements; // Services desired post scan
271  QEventLoop m_eventLoop;
272 };
273 
274 #endif // CHANNEL_IMPORTER_H
ChannelImporter::kSCTEConflicting
@ kSCTEConflicting
Definition: channelimporter.h:133
ChannelImporterBasicStats::m_chanNumCnt
QMap< QString, uint > m_chanNumCnt
Definition: channelimporter.h:54
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:28
ChannelImporter::m_isInteractive
bool m_isInteractive
Definition: channelimporter.h:257
ChannelImporter::kUpdateIgnoreAll
@ kUpdateIgnoreAll
Definition: channelimporter.h:115
mythtvexp.h
kOCTCancel
@ kOCTCancel
Definition: channelimporter.h:30
ChannelImporter::m_doInsert
bool m_doInsert
Definition: channelimporter.h:259
ChannelImporter::kDVBConflicting
@ kDVBConflicting
Definition: channelimporter.h:132
ChannelImporter::kNTSCNonConflicting
@ kNTSCNonConflicting
Definition: channelimporter.h:127
ChannelImporter::kUpdateManual
@ kUpdateManual
Definition: channelimporter.h:114
ChannelImporter::kChannelTypeConflictingFirst
@ kChannelTypeConflictingFirst
Definition: channelimporter.h:130
ChannelImporterUniquenessStats::m_uniqueProgNum
uint m_uniqueProgNum
Definition: channelimporter.h:62
ChannelImporter::UpdateAction
UpdateAction
Definition: channelimporter.h:111
ChannelImporterBasicStats::m_atscChannels
ChanStats m_atscChannels
Definition: channelimporter.h:43
ChannelImporter::m_doDelete
bool m_doDelete
Definition: channelimporter.h:258
ChannelImporterBasicStats::m_atscNumCnt
QMap< uint, uint > m_atscNumCnt
Definition: channelimporter.h:51
ChannelImporter::m_serviceRequirements
ServiceRequirements m_serviceRequirements
Definition: channelimporter.h:270
kOCTOk
@ kOCTOk
Definition: channelimporter.h:31
ChannelInsertInfo
Definition: channelinfo.h:133
ChannelImporter::DeleteAction
DeleteAction
Definition: channelimporter.h:98
ChannelImporter::m_useGui
bool m_useGui
Definition: channelimporter.h:256
ChanStats
std::array< uint, 3 > ChanStats
Definition: channelimporter.h:35
ChannelImporter::kMPEGConflicting
@ kMPEGConflicting
Definition: channelimporter.h:134
channelscantypes.h
ChannelImporterBasicStats::m_atscMajCnt
QMap< uint, uint > m_atscMajCnt
Definition: channelimporter.h:53
ChannelImporter::kDeleteAll
@ kDeleteAll
Definition: channelimporter.h:100
ChannelImporter::kDVBNonConflicting
@ kDVBNonConflicting
Definition: channelimporter.h:124
ChannelImporter::kSCTENonConflicting
@ kSCTENonConflicting
Definition: channelimporter.h:125
scaninfo.h
ChannelImporterBasicStats::ChannelImporterBasicStats
ChannelImporterBasicStats()=default
ChannelImporter::kInsertManual
@ kInsertManual
Definition: channelimporter.h:108
uint
unsigned int uint
Definition: compat.h:79
ChannelImporter::m_eventLoop
QEventLoop m_eventLoop
Definition: channelimporter.h:271
ScanDTVTransportList
std::vector< ScanDTVTransport > ScanDTVTransportList
Definition: dtvmultiplex.h:143
ChannelImporter::kDeleteManual
@ kDeleteManual
Definition: channelimporter.h:101
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
ChannelImporterUniquenessStats::m_uniqueChanNum
uint m_uniqueChanNum
Definition: channelimporter.h:65
ChannelImporterBasicStats::m_ntscChannels
ChanStats m_ntscChannels
Definition: channelimporter.h:47
ChannelImporterBasicStats::m_progNumCnt
QMap< uint, uint > m_progNumCnt
Definition: channelimporter.h:50
ChannelImporter::ChannelImporter
ChannelImporter(bool gui, bool interactive, bool _delete, bool insert, bool save, bool fta_only, bool lcn_only, bool complete_only, bool full_channel_search, bool remove_duplicates, ServiceRequirements service_requirements, bool success=false)
Definition: channelimporter.h:75
kOCTCancelAll
@ kOCTCancelAll
Definition: channelimporter.h:29
ChannelImporter::kMPEGNonConflicting
@ kMPEGNonConflicting
Definition: channelimporter.h:126
ChannelImporter::kDeleteIgnoreAll
@ kDeleteIgnoreAll
Definition: channelimporter.h:102
ChannelImporter::kInsertAll
@ kInsertAll
Definition: channelimporter.h:107
ChannelImporter
Definition: channelimporter.h:70
ChannelImporterUniquenessStats::m_uniqueTotal
uint m_uniqueTotal
Definition: channelimporter.h:66
ChannelImporter::kUpdateAll
@ kUpdateAll
Definition: channelimporter.h:113
ChannelImporterUniquenessStats::m_uniqueAtscMin
uint m_uniqueAtscMin
Definition: channelimporter.h:64
ChannelImporterUniquenessStats::m_maxAtscMajCnt
uint m_maxAtscMajCnt
Definition: channelimporter.h:67
build_compdb.action
action
Definition: build_compdb.py:9
ChannelImporter::InsertAction
InsertAction
Definition: channelimporter.h:105
ChannelImporterBasicStats
Definition: channelimporter.h:37
ChannelImporterBasicStats::m_scteChannels
ChanStats m_scteChannels
Definition: channelimporter.h:45
ChannelImporterUniquenessStats::m_uniqueAtscNum
uint m_uniqueAtscNum
Definition: channelimporter.h:63
ServiceRequirements
ServiceRequirements
Definition: channelscantypes.h:4
ChannelImporterBasicStats::m_dvbChannels
ChanStats m_dvbChannels
Definition: channelimporter.h:44
ChannelImporterBasicStats::m_mpegChannels
ChanStats m_mpegChannels
Definition: channelimporter.h:46
mythmainwindow.h
ChannelImporterUniquenessStats::ChannelImporterUniquenessStats
ChannelImporterUniquenessStats()=default
ChannelImporter::kInsertIgnoreAll
@ kInsertIgnoreAll
Definition: channelimporter.h:109
ChannelImporter::m_doSave
bool m_doSave
Definition: channelimporter.h:260
ChannelImporterBasicStats::m_atscMinCnt
QMap< uint, uint > m_atscMinCnt
Definition: channelimporter.h:52
ChannelImporter::ChannelType
ChannelType
Definition: channelimporter.h:118
MythMainWindow
Definition: mythmainwindow.h:28
ChannelImporterUniquenessStats
Definition: channelimporter.h:57
ChannelImporter::kNTSCConflicting
@ kNTSCConflicting
Definition: channelimporter.h:135
ScanDTVTransport
Definition: dtvmultiplex.h:115
ChannelImporter::kDeleteInvisibleAll
@ kDeleteInvisibleAll
Definition: channelimporter.h:103
kOCTOkAll
@ kOCTOkAll
Definition: channelimporter.h:32