MythTV  master
paneatsc.h
Go to the documentation of this file.
1 /* -*- Mode: c++ -*-
2  * vim: set expandtab tabstop=4 shiftwidth=4:
3  */
4 
5 #ifndef PANE_ATSC_H
6 #define PANE_ATSC_H
7 
8 #include <algorithm>
9 using namespace std;
10 
11 // MythTV headers
13 #include "frequencytablesetting.h"
14 #include "modulationsetting.h"
15 #include "frequencytables.h"
16 
17 class PaneATSC : public GroupSetting
18 {
19  Q_OBJECT
20 
21  public:
22  PaneATSC(const QString &target, StandardSetting *setting) :
23  m_atscTable(new ScanFrequencyTable()),
24  m_atscModulation(new ScanATSCModulation())
25  {
26  setVisible(false);
27 
28  connect(m_atscTable, SIGNAL(valueChanged( const QString&)),
29  this, SLOT( FreqTableChanged(const QString&)));
30 
31  connect(m_atscModulation, SIGNAL(valueChanged( const QString&)),
32  this, SLOT( ModulationChanged(const QString&)));
33 
34  auto *range = new GroupSetting();
35  m_transportStart = new TransMythUIComboBoxSetting();
36  m_transportEnd = new TransMythUIComboBoxSetting();
37  m_transportCount = new TransTextEditSetting();
38  range->setLabel(tr("Scanning Range"));
39  range->addChild(m_transportStart);
40  range->addChild(m_transportEnd);
41  range->addChild(m_transportCount);
42 
43  setting->addTargetedChildren(target,
44  {this, m_atscTable, m_atscModulation, range});
45 
46  connect(m_transportStart, SIGNAL(valueChanged( const QString&)),
47  this, SLOT( TransportRangeChanged(const QString&)));
48  connect(m_transportEnd, SIGNAL(valueChanged( const QString&)),
49  this, SLOT( TransportRangeChanged(const QString&)));
50 
51  ResetTransportRange();
52  }
53 
54  ~PaneATSC() override
55  {
56  while (!m_tables.empty())
57  {
58  delete m_tables.back();
59  m_tables.pop_back();
60  }
61  }
62 
63  void SetFrequencyTable(const QString &atsc_table)
64  { m_atscTable->setValue(atsc_table); }
65 
66  QString GetFrequencyTable(void) const
67  { return m_atscTable->getValue(); }
68  QString GetModulation(void) const
69  { return m_atscModulation->getValue(); }
71  QString &start, QString &end) const
72  {
73  if (!m_transportStart->size() || !m_transportEnd->size())
74  return false;
75 
76  start = m_transportStart->getValue();
77  end = m_transportEnd->getValue();
78 
79  return !start.isEmpty() && !end.isEmpty();
80  }
81 
82  protected slots:
83  void FreqTableChanged(const QString &freqtbl)
84  {
85  if (freqtbl == "us")
86  m_atscModulation->setValue(0);
87  else if (m_atscModulation->getValue() == "vsb8")
88  m_atscModulation->setValue(1);
89 
90  ResetTransportRange();
91  }
92 
93  void ModulationChanged(const QString &/*modulation*/)
94  {
95  ResetTransportRange();
96  }
97 
98  void TransportRangeChanged(const QString &/*range*/)
99  {
100  int a = m_transportStart->getValueIndex(m_transportStart->getValue());
101  int b = m_transportEnd->getValueIndex(m_transportEnd->getValue());
102  if (b < a)
103  {
104  m_transportEnd->setValue(m_transportStart->getValue());
105  b = a;
106  }
107 
108  int diff = max(b + 1 - a, 0);
109  m_transportCount->setValue(QString::number(diff));
110  }
111 
112  protected:
114  {
115  m_transportStart->clearSelections();
116  m_transportEnd->clearSelections();
117  m_transportCount->setValue(QString::number(0));
118 
119  FetchFrequencyTables();
120 
121  bool first = true;
122  for (auto it = m_tables.begin(); it != m_tables.end(); ++it)
123  {
124  auto next = it;
125  ++next;
126 
127  const FrequencyTable &ft = **it;
128  int name_num = ft.m_nameOffset;
129  QString strNameFormat = ft.m_nameFormat;
131  while (freq <= ft.m_frequencyEnd)
132  {
133  QString name = strNameFormat;
134  if (strNameFormat.indexOf("%") >= 0)
135  name = strNameFormat.arg(name_num);
136 
137  m_transportStart->addSelection(name, name, first);
138  first = false;
139 
140  bool last = (next == m_tables.end()) &&
141  ((freq + ft.m_frequencyStep) >= ft.m_frequencyEnd);
142  m_transportEnd->addSelection(name, name, last);
143 
144  name_num++;
145  freq += ft.m_frequencyStep;
146  }
147  }
148  }
149 
151  {
152  QString format = "atsc";
153  QString modulation = GetModulation();
154  QString country = GetFrequencyTable();
155 
156  const QString new_tables_sig =
157  QString("%1_%2_%3").arg(format).arg(modulation).arg(country);
158 
159  if (new_tables_sig != m_tablesSig)
160  {
161  while (!m_tables.empty())
162  {
163  delete m_tables.back();
164  m_tables.pop_back();
165  }
166 
167  m_tablesSig = new_tables_sig;
168 
169  m_tables = get_matching_freq_tables(
170  format, modulation, country);
171  }
172  }
173 
174  protected:
175  ScanFrequencyTable *m_atscTable {nullptr};
176  ScanATSCModulation *m_atscModulation {nullptr};
177  TransMythUIComboBoxSetting *m_transportStart {nullptr};
178  TransMythUIComboBoxSetting *m_transportEnd {nullptr};
179  TransTextEditSetting *m_transportCount {nullptr};
180  QString m_tablesSig;
182 };
183 
184 #endif // PANE_ATSC_H
PaneATSC::SetFrequencyTable
void SetFrequencyTable(const QString &atsc_table)
Definition: paneatsc.h:63
PaneATSC::FreqTableChanged
void FreqTableChanged(const QString &freqtbl)
Definition: paneatsc.h:83
PaneATSC::PaneATSC
PaneATSC(const QString &target, StandardSetting *setting)
Definition: paneatsc.h:22
FrequencyTable
Definition: frequencytables.h:40
ScanATSCModulation
Definition: modulationsetting.h:40
PaneATSC::ResetTransportRange
void ResetTransportRange(void)
Definition: paneatsc.h:113
TransMythUIComboBoxSetting
Definition: standardsettings.h:270
TransTextEditSetting
Definition: standardsettings.h:159
PaneATSC::ModulationChanged
void ModulationChanged(const QString &)
Definition: paneatsc.h:93
FrequencyTable::m_nameFormat
QString m_nameFormat
pretty name format
Definition: frequencytables.h:96
slots
unsigned int slots[4]
Definition: element.cpp:38
PaneATSC::GetFrequencyTable
QString GetFrequencyTable(void) const
Definition: paneatsc.h:66
PaneATSC
Definition: paneatsc.h:18
FrequencyTable::m_frequencyStep
uint m_frequencyStep
The step in frequency.
Definition: frequencytables.h:100
PaneATSC::m_tables
freq_table_list_t m_tables
Definition: paneatsc.h:181
frequencytablesetting.h
modulationsetting.h
uint
unsigned int uint
Definition: compat.h:140
PaneATSC::~PaneATSC
~PaneATSC() override
Definition: paneatsc.h:54
PaneATSC::m_tablesSig
QString m_tablesSig
Definition: paneatsc.h:180
channelscanmiscsettings.h
get_matching_freq_tables
freq_table_list_t get_matching_freq_tables(const QString &format, const QString &modulation, const QString &country)
Definition: frequencytables.cpp:246
PaneATSC::GetFrequencyTableRange
bool GetFrequencyTableRange(QString &start, QString &end) const
Definition: paneatsc.h:70
FrequencyTable::m_frequencyEnd
uint64_t m_frequencyEnd
The ending centre frequency.
Definition: frequencytables.h:99
next
PictureAttribute next(PictureAttributeSupported Supported, PictureAttribute Attribute)
Definition: videoouttypes.h:350
frequencytables.h
freq
uint32_t freq[4]
Definition: element.cpp:44
ScanFrequencyTable
Definition: frequencytablesetting.h:11
PaneATSC::TransportRangeChanged
void TransportRangeChanged(const QString &)
Definition: paneatsc.h:98
FrequencyTable::m_nameOffset
int m_nameOffset
Offset to add to the pretty name.
Definition: frequencytables.h:97
StandardSetting
Definition: standardsettings.h:30
PaneATSC::GetModulation
QString GetModulation(void) const
Definition: paneatsc.h:68
StandardSetting::addTargetedChildren
void addTargetedChildren(const QString &value, std::initializer_list< StandardSetting * > settings)
Definition: standardsettings.cpp:100
FrequencyTable::m_frequencyStart
uint64_t m_frequencyStart
The staring centre frequency.
Definition: frequencytables.h:98
freq_table_list_t
vector< const FrequencyTable * > freq_table_list_t
Definition: frequencytables.h:26
PaneATSC::FetchFrequencyTables
void FetchFrequencyTables(void)
Definition: paneatsc.h:150
GroupSetting
Definition: standardsettings.h:433