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