00001
00002
00003
00004
00005 #ifndef _PANE_ATSC_H_
00006 #define _PANE_ATSC_H_
00007
00008 #include <algorithm>
00009 using namespace std;
00010
00011
00012 #include "channelscanmiscsettings.h"
00013 #include "frequencytablesetting.h"
00014 #include "modulationsetting.h"
00015 #include "frequencytables.h"
00016
00017 class PaneATSC : public VerticalConfigurationGroup
00018 {
00019 Q_OBJECT
00020
00021 public:
00022 PaneATSC() :
00023 VerticalConfigurationGroup(false, false, true, false),
00024 atsc_table(new ScanFrequencyTable()),
00025 atsc_modulation(new ScanATSCModulation())
00026 {
00027 addChild(atsc_table);
00028 addChild(atsc_modulation);
00029
00030 connect(atsc_table, SIGNAL(valueChanged( const QString&)),
00031 this, SLOT( FreqTableChanged(const QString&)));
00032
00033 connect(atsc_modulation, SIGNAL(valueChanged( const QString&)),
00034 this, SLOT( ModulationChanged(const QString&)));
00035
00036 HorizontalConfigurationGroup *range =
00037 new HorizontalConfigurationGroup(false,false,true,true);
00038 transport_start = new TransComboBoxSetting();
00039 transport_end = new TransComboBoxSetting();
00040 transport_count = new TransLabelSetting();
00041 TransLabelSetting *label = new TransLabelSetting();
00042 label->setLabel(tr("Scanning Range"));
00043 range->addChild(label);
00044 range->addChild(transport_start);
00045 range->addChild(transport_end);
00046 range->addChild(transport_count);
00047 addChild(range);
00048
00049 connect(transport_start, SIGNAL(valueChanged( const QString&)),
00050 this, SLOT( TransportRangeChanged(const QString&)));
00051 connect(transport_end, SIGNAL(valueChanged( const QString&)),
00052 this, SLOT( TransportRangeChanged(const QString&)));
00053
00054 ResetTransportRange();
00055 }
00056
00057 ~PaneATSC()
00058 {
00059 while (!tables.empty())
00060 {
00061 delete tables.back();
00062 tables.pop_back();
00063 }
00064 }
00065
00066 QString GetFrequencyTable(void) const
00067 { return atsc_table->getValue(); }
00068 QString GetModulation(void) const
00069 { return atsc_modulation->getValue(); }
00070 bool GetFrequencyTableRange(
00071 QString &start, QString &end) const
00072 {
00073 if (!transport_start->size() || !transport_end->size())
00074 return false;
00075
00076 start = transport_start->getValue();
00077 end = transport_end->getValue();
00078
00079 return !start.isEmpty() && !end.isEmpty();
00080 }
00081
00082 protected slots:
00083 void FreqTableChanged(const QString &freqtbl)
00084 {
00085 if (freqtbl == "us")
00086 atsc_modulation->setValue(0);
00087 else if (atsc_modulation->getValue() == "vsb8")
00088 atsc_modulation->setValue(1);
00089
00090 ResetTransportRange();
00091 }
00092
00093 void ModulationChanged(const QString &modulation)
00094 {
00095 ResetTransportRange();
00096 }
00097
00098 void TransportRangeChanged(const QString&)
00099 {
00100 int a = transport_start->getValueIndex(transport_start->getValue());
00101 int b = transport_end->getValueIndex(transport_end->getValue());
00102 if (b < a)
00103 {
00104 transport_end->setValue(transport_start->getValue());
00105 b = a;
00106 }
00107
00108 int diff = max(b + 1 - a, 0);
00109 transport_count->setValue(QString::number(diff));
00110 }
00111
00112 protected:
00113 void ResetTransportRange(void)
00114 {
00115 transport_start->clearSelections();
00116 transport_end->clearSelections();
00117 transport_count->setValue(QString::number(0));
00118
00119 FetchFrequencyTables();
00120
00121 bool first = true;
00122 freq_table_list_t::iterator it = tables.begin();
00123 for (; it != tables.end(); ++it)
00124 {
00125 freq_table_list_t::iterator next = it;
00126 ++next;
00127
00128 const FrequencyTable &ft = **it;
00129 int name_num = ft.name_offset;
00130 QString strNameFormat = ft.name_format;
00131 uint freq = ft.frequencyStart;
00132 while (freq <= ft.frequencyEnd)
00133 {
00134 QString name = strNameFormat;
00135 if (strNameFormat.indexOf("%") >= 0)
00136 name = strNameFormat.arg(name_num);
00137
00138 transport_start->addSelection(name, name, first);
00139 first = false;
00140
00141 bool last = (next == tables.end()) &&
00142 ((freq + ft.frequencyStep) >= ft.frequencyEnd);
00143 transport_end->addSelection(name, name, last);
00144
00145 name_num++;
00146 freq += ft.frequencyStep;
00147 }
00148 }
00149 }
00150
00151 void FetchFrequencyTables(void)
00152 {
00153 QString format = "atsc";
00154 QString modulation = GetModulation();
00155 QString country = GetFrequencyTable();
00156
00157 const QString new_tables_sig =
00158 QString("%1_%2_%3").arg(format).arg(modulation).arg(country);
00159
00160 if (new_tables_sig != tables_sig)
00161 {
00162 while (!tables.empty())
00163 {
00164 delete tables.back();
00165 tables.pop_back();
00166 }
00167
00168 tables_sig = new_tables_sig;
00169
00170 tables = get_matching_freq_tables(
00171 format, modulation, country);
00172 }
00173 }
00174
00175 protected:
00176 ScanFrequencyTable *atsc_table;
00177 ScanATSCModulation *atsc_modulation;
00178 TransComboBoxSetting *transport_start;
00179 TransComboBoxSetting *transport_end;
00180 TransLabelSetting *transport_count;
00181 QString old_freq_table;
00182 QString tables_sig;
00183 freq_table_list_t tables;
00184 };
00185
00186 #endif // _PANE_ATSC_H_