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_atsc_table(new ScanFrequencyTable()),
24  m_atsc_modulation(new ScanATSCModulation())
25  {
26  setVisible(false);
27 
28  connect(m_atsc_table, SIGNAL(valueChanged( const QString&)),
29  this, SLOT( FreqTableChanged(const QString&)));
30 
31  connect(m_atsc_modulation, SIGNAL(valueChanged( const QString&)),
32  this, SLOT( ModulationChanged(const QString&)));
33 
34  GroupSetting *range = new GroupSetting();
35  m_transport_start = new TransMythUIComboBoxSetting();
36  m_transport_end = new TransMythUIComboBoxSetting();
37  m_transport_count = new TransTextEditSetting();
38  range->setLabel(tr("Scanning Range"));
39  range->addChild(m_transport_start);
40  range->addChild(m_transport_end);
41  range->addChild(m_transport_count);
42 
43  setting->addTargetedChildren(target,
44  {this, m_atsc_table, m_atsc_modulation, range});
45 
46  connect(m_transport_start, SIGNAL(valueChanged( const QString&)),
47  this, SLOT( TransportRangeChanged(const QString&)));
48  connect(m_transport_end, SIGNAL(valueChanged( const QString&)),
49  this, SLOT( TransportRangeChanged(const QString&)));
50 
51  ResetTransportRange();
52  }
53 
55  {
56  while (!m_tables.empty())
57  {
58  delete m_tables.back();
59  m_tables.pop_back();
60  }
61  }
62 
63  QString GetFrequencyTable(void) const
64  { return m_atsc_table->getValue(); }
65  QString GetModulation(void) const
66  { return m_atsc_modulation->getValue(); }
68  QString &start, QString &end) const
69  {
70  if (!m_transport_start->size() || !m_transport_end->size())
71  return false;
72 
73  start = m_transport_start->getValue();
74  end = m_transport_end->getValue();
75 
76  return !start.isEmpty() && !end.isEmpty();
77  }
78 
79  protected slots:
80  void FreqTableChanged(const QString &freqtbl)
81  {
82  if (freqtbl == "us")
83  m_atsc_modulation->setValue(0);
84  else if (m_atsc_modulation->getValue() == "vsb8")
85  m_atsc_modulation->setValue(1);
86 
87  ResetTransportRange();
88  }
89 
90  void ModulationChanged(const QString &/*modulation*/)
91  {
92  ResetTransportRange();
93  }
94 
95  void TransportRangeChanged(const QString&)
96  {
97  int a = m_transport_start->getValueIndex(m_transport_start->getValue());
98  int b = m_transport_end->getValueIndex(m_transport_end->getValue());
99  if (b < a)
100  {
101  m_transport_end->setValue(m_transport_start->getValue());
102  b = a;
103  }
104 
105  int diff = max(b + 1 - a, 0);
106  m_transport_count->setValue(QString::number(diff));
107  }
108 
109  protected:
111  {
112  m_transport_start->clearSelections();
113  m_transport_end->clearSelections();
114  m_transport_count->setValue(QString::number(0));
115 
116  FetchFrequencyTables();
117 
118  bool first = true;
119  freq_table_list_t::iterator it = m_tables.begin();
120  for (; it != m_tables.end(); ++it)
121  {
122  freq_table_list_t::iterator next = it;
123  ++next;
124 
125  const FrequencyTable &ft = **it;
126  int name_num = ft.m_nameOffset;
127  QString strNameFormat = ft.m_nameFormat;
129  while (freq <= ft.m_frequencyEnd)
130  {
131  QString name = strNameFormat;
132  if (strNameFormat.indexOf("%") >= 0)
133  name = strNameFormat.arg(name_num);
134 
135  m_transport_start->addSelection(name, name, first);
136  first = false;
137 
138  bool last = (next == m_tables.end()) &&
139  ((freq + ft.m_frequencyStep) >= ft.m_frequencyEnd);
140  m_transport_end->addSelection(name, name, last);
141 
142  name_num++;
143  freq += ft.m_frequencyStep;
144  }
145  }
146  }
147 
149  {
150  QString format = "atsc";
151  QString modulation = GetModulation();
152  QString country = GetFrequencyTable();
153 
154  const QString new_tables_sig =
155  QString("%1_%2_%3").arg(format).arg(modulation).arg(country);
156 
157  if (new_tables_sig != m_tables_sig)
158  {
159  while (!m_tables.empty())
160  {
161  delete m_tables.back();
162  m_tables.pop_back();
163  }
164 
165  m_tables_sig = new_tables_sig;
166 
167  m_tables = get_matching_freq_tables(
168  format, modulation, country);
169  }
170  }
171 
172  protected:
173  ScanFrequencyTable *m_atsc_table {nullptr};
174  ScanATSCModulation *m_atsc_modulation {nullptr};
175  TransMythUIComboBoxSetting *m_transport_start {nullptr};
176  TransMythUIComboBoxSetting *m_transport_end {nullptr};
177  TransTextEditSetting *m_transport_count {nullptr};
178 // QString m_old_freq_table;
179  QString m_tables_sig;
181 };
182 
183 #endif // _PANE_ATSC_H_
PaneATSC(const QString &target, StandardSetting *setting)
Definition: paneatsc.h:22
~PaneATSC()
Definition: paneatsc.h:54
QString m_tables_sig
Definition: paneatsc.h:179
unsigned int slots[4]
Definition: element.c:38
QString GetModulation(void) const
Definition: paneatsc.h:65
struct exc__state * last
Definition: pxsup2dast.c:98
freq_table_list_t m_tables
Definition: paneatsc.h:180
uint64_t m_frequencyEnd
The ending centre frequency.
vector< const FrequencyTable * > freq_table_list_t
unsigned int uint
Definition: compat.h:140
freq_table_list_t get_matching_freq_tables(const QString &format, const QString &modulation, const QString &country)
uint32_t freq[4]
Definition: element.c:44
int m_nameOffset
Offset to add to the pretty name.
QString m_nameFormat
pretty name format
unsigned char b
Definition: ParseText.cpp:329
uint64_t m_frequencyStart
The staring centre frequency.
virtual void setLabel(QString str)
bool GetFrequencyTableRange(QString &start, QString &end) const
Definition: paneatsc.h:67
void FetchFrequencyTables(void)
Definition: paneatsc.h:148
uint m_frequencyStep
The step in frequency.
const char * name
Definition: ParseText.cpp:328
virtual void addChild(StandardSetting *child)
void ResetTransportRange(void)
Definition: paneatsc.h:110
QString GetFrequencyTable(void) const
Definition: paneatsc.h:63
PictureAttribute next(PictureAttributeSupported supported, PictureAttribute attribute)
void addTargetedChildren(const QString &value, std::initializer_list< StandardSetting * > settings)
void FreqTableChanged(const QString &freqtbl)
Definition: paneatsc.h:80
void TransportRangeChanged(const QString &)
Definition: paneatsc.h:95
void ModulationChanged(const QString &)
Definition: paneatsc.h:90