00001
00002
00003
00004
00005
00006
00007
00008 #include <cmath>
00009
00010
00011 #include "mythcontext.h"
00012 #include "mythdbcon.h"
00013 #include "diseqcsettings.h"
00014
00015
00016
00017 static GlobalLineEdit *DiSEqCLatitude(void)
00018 {
00019 GlobalLineEdit *gc = new GlobalLineEdit("latitude");
00020 gc->setLabel("Latitude");
00021 gc->setHelpText(
00022 DeviceTree::tr("The Cartesian latitude for your location.") + " " +
00023 DeviceTree::tr("Use negative numbers for southern "
00024 "and western coordinates."));
00025 return gc;
00026 }
00027
00028 static GlobalLineEdit *DiSEqCLongitude(void)
00029 {
00030 GlobalLineEdit *gc = new GlobalLineEdit("longitude");
00031 gc->setLabel("Longitude");
00032 gc->setHelpText(
00033 DeviceTree::tr("The Cartesian longitude for your location.") + " " +
00034 DeviceTree::tr("Use negative numbers for southern "
00035 "and western coordinates."));
00036 return gc;
00037 }
00038
00040
00041 class DeviceTypeSetting : public ComboBoxSetting, public Storage
00042 {
00043 public:
00044 DeviceTypeSetting(DiSEqCDevDevice &device) :
00045 ComboBoxSetting(this), m_device(device)
00046 {
00047 setLabel(DeviceTree::tr("Device Type"));
00048 addSelection(DeviceTree::tr("Switch"),
00049 QString::number((uint) DiSEqCDevDevice::kTypeSwitch));
00050 addSelection(DeviceTree::tr("Rotor"),
00051 QString::number((uint) DiSEqCDevDevice::kTypeRotor));
00052 addSelection(DeviceTree::tr("LNB"),
00053 QString::number((uint) DiSEqCDevDevice::kTypeLNB));
00054 }
00055
00056 virtual void load(void)
00057 {
00058 QString tmp = QString::number((uint) m_device.GetDeviceType());
00059 setValue(getValueIndex(tmp));
00060 }
00061
00062 virtual void save(void)
00063 {
00064 m_device.SetDeviceType(
00065 (DiSEqCDevDevice::dvbdev_t) getValue().toUInt());
00066 }
00067
00068 virtual void save(QString ) { }
00069
00070 private:
00071 DiSEqCDevDevice &m_device;
00072 };
00073
00075
00076 class DeviceDescrSetting : public LineEditSetting, public Storage
00077 {
00078 public:
00079 DeviceDescrSetting(DiSEqCDevDevice &device) :
00080 LineEditSetting(this), m_device(device)
00081 {
00082 setLabel(DeviceTree::tr("Description"));
00083 QString help = DeviceTree::tr(
00084 "Optional descriptive name for this device, to "
00085 "make it easier to configure settings later.");
00086 setHelpText(help);
00087 }
00088
00089 virtual void load(void)
00090 {
00091 setValue(m_device.GetDescription());
00092 }
00093
00094 virtual void save(void)
00095 {
00096 m_device.SetDescription(getValue());
00097 }
00098
00099 virtual void save(QString ) { }
00100
00101 private:
00102 DiSEqCDevDevice &m_device;
00103 };
00104
00105
00107
00108 class DeviceRepeatSetting : public SpinBoxSetting, public Storage
00109 {
00110 public:
00111 DeviceRepeatSetting(DiSEqCDevDevice &device) :
00112 SpinBoxSetting(this, 1, 5, 1), m_device(device)
00113 {
00114 setLabel(DeviceTree::tr("Repeat Count"));
00115 QString help = DeviceTree::tr(
00116 "Number of times to repeat DiSEqC commands sent to this device. "
00117 "Larger values may help with less reliable devices.");
00118 setHelpText(help);
00119 }
00120
00121 virtual void load(void)
00122 {
00123 setValue(m_device.GetRepeatCount());
00124 }
00125
00126 virtual void save(void)
00127 {
00128 m_device.SetRepeatCount(getValue().toUInt());
00129 }
00130
00131 virtual void save(QString ) { }
00132
00133 private:
00134 DiSEqCDevDevice &m_device;
00135 };
00136
00138
00139 class SwitchTypeSetting : public ComboBoxSetting, public Storage
00140 {
00141 public:
00142 SwitchTypeSetting(DiSEqCDevSwitch &switch_dev) :
00143 ComboBoxSetting(this), m_switch(switch_dev)
00144 {
00145 setLabel(DeviceTree::tr("Switch Type"));
00146 setHelpText(DeviceTree::tr("Select the type of switch from the list."));
00147
00148 addSelection(DeviceTree::tr("Tone"),
00149 QString::number((uint) DiSEqCDevSwitch::kTypeTone));
00150 addSelection(DeviceTree::tr("Voltage"),
00151 QString::number((uint) DiSEqCDevSwitch::kTypeVoltage));
00152 addSelection(DeviceTree::tr("Mini DiSEqC"),
00153 QString::number((uint) DiSEqCDevSwitch::kTypeMiniDiSEqC));
00154 addSelection(DeviceTree::tr("DiSEqC"),
00155 QString::number((uint)
00156 DiSEqCDevSwitch::kTypeDiSEqCCommitted));
00157 addSelection(DeviceTree::tr("DiSEqC (Uncommitted)"),
00158 QString::number((uint)
00159 DiSEqCDevSwitch::kTypeDiSEqCUncommitted));
00160 addSelection(DeviceTree::tr("Legacy SW21"),
00161 QString::number((uint) DiSEqCDevSwitch::kTypeLegacySW21));
00162 addSelection(DeviceTree::tr("Legacy SW42"),
00163 QString::number((uint) DiSEqCDevSwitch::kTypeLegacySW42));
00164 addSelection(DeviceTree::tr("Legacy SW64"),
00165 QString::number((uint) DiSEqCDevSwitch::kTypeLegacySW64));
00166 }
00167
00168 virtual void load(void)
00169 {
00170 setValue(getValueIndex(QString::number((uint) m_switch.GetType())));
00171 }
00172
00173 virtual void save(void)
00174 {
00175 m_switch.SetType((DiSEqCDevSwitch::dvbdev_switch_t)
00176 getValue().toUInt());
00177 }
00178
00179 virtual void save(QString ) { }
00180
00181 private:
00182 DiSEqCDevSwitch &m_switch;
00183 };
00184
00186
00187 class SwitchPortsSetting : public LineEditSetting, public Storage
00188 {
00189 public:
00190 SwitchPortsSetting(DiSEqCDevSwitch &switch_dev) :
00191 LineEditSetting(this), m_switch(switch_dev)
00192 {
00193 setLabel(DeviceTree::tr("Number of ports"));
00194 setHelpText(DeviceTree::tr("The number of ports this switch has."));
00195 }
00196
00197 virtual void load(void)
00198 {
00199 setValue(QString::number(m_switch.GetNumPorts()));
00200 }
00201
00202 virtual void save(void)
00203 {
00204 m_switch.SetNumPorts(getValue().toUInt());
00205 }
00206
00207 virtual void save(QString ) { }
00208
00209 private:
00210 DiSEqCDevSwitch &m_switch;
00211 };
00212
00214
00215 SwitchConfig::SwitchConfig(DiSEqCDevSwitch &switch_dev)
00216 {
00217 ConfigurationGroup *group =
00218 new VerticalConfigurationGroup(false, false);
00219 group->setLabel(DeviceTree::tr("Switch Configuration"));
00220
00221 group->addChild(new DeviceDescrSetting(switch_dev));
00222 group->addChild(new DeviceRepeatSetting(switch_dev));
00223 m_type = new SwitchTypeSetting(switch_dev);
00224 group->addChild(m_type);
00225 m_ports = new SwitchPortsSetting(switch_dev);
00226 group->addChild(m_ports);
00227
00228 connect(m_type, SIGNAL(valueChanged(const QString&)),
00229 this, SLOT( update(void)));
00230
00231 addChild(group);
00232 }
00233
00234 void SwitchConfig::update(void)
00235 {
00236 switch ((DiSEqCDevSwitch::dvbdev_switch_t) m_type->getValue().toUInt())
00237 {
00238 case DiSEqCDevSwitch::kTypeTone:
00239 case DiSEqCDevSwitch::kTypeVoltage:
00240 case DiSEqCDevSwitch::kTypeMiniDiSEqC:
00241 case DiSEqCDevSwitch::kTypeLegacySW21:
00242 case DiSEqCDevSwitch::kTypeLegacySW42:
00243 m_ports->setValue("2");
00244 m_ports->setEnabled(false);
00245 break;
00246 case DiSEqCDevSwitch::kTypeLegacySW64:
00247 m_ports->setValue("3");
00248 m_ports->setEnabled(false);
00249 break;
00250 case DiSEqCDevSwitch::kTypeDiSEqCCommitted:
00251 case DiSEqCDevSwitch::kTypeDiSEqCUncommitted:
00252 m_ports->setEnabled(true);
00253 break;
00254 }
00255 }
00256
00258
00259 class RotorTypeSetting : public ComboBoxSetting, public Storage
00260 {
00261 public:
00262 RotorTypeSetting(DiSEqCDevRotor &rotor) :
00263 ComboBoxSetting(this), m_rotor(rotor)
00264 {
00265 setLabel(DeviceTree::tr("Rotor Type"));
00266 setHelpText(DeviceTree::tr("Select the type of rotor from the list."));
00267 addSelection(DeviceTree::tr("DiSEqC 1.2"),
00268 QString::number((uint) DiSEqCDevRotor::kTypeDiSEqC_1_2));
00269 addSelection(DeviceTree::tr("DiSEqC 1.3 (GotoX/USALS)"),
00270 QString::number((uint) DiSEqCDevRotor::kTypeDiSEqC_1_3));
00271 }
00272
00273 virtual void load(void)
00274 {
00275 setValue(getValueIndex(QString::number((uint)m_rotor.GetType())));
00276 }
00277
00278 virtual void save(void)
00279 {
00280 m_rotor.SetType((DiSEqCDevRotor::dvbdev_rotor_t)getValue().toUInt());
00281 }
00282
00283 virtual void save(QString ) { }
00284
00285 private:
00286 DiSEqCDevRotor &m_rotor;
00287 };
00288
00290
00291 class RotorLoSpeedSetting : public LineEditSetting, public Storage
00292 {
00293 public:
00294 RotorLoSpeedSetting(DiSEqCDevRotor &rotor) :
00295 LineEditSetting(this), m_rotor(rotor)
00296 {
00297 setLabel(DeviceTree::tr("Rotor Low Speed (deg/sec)"));
00298 QString help = DeviceTree::tr(
00299 "To allow the approximate monitoring of rotor movement, enter "
00300 "the rated angular speed of the rotor when powered at 13V.");
00301 setHelpText(help);
00302 }
00303
00304 virtual void load(void)
00305 {
00306 setValue(QString::number(m_rotor.GetLoSpeed()));
00307 }
00308
00309 virtual void save(void)
00310 {
00311 m_rotor.SetLoSpeed(getValue().toDouble());
00312 }
00313
00314 virtual void save(QString ) { }
00315
00316 private:
00317 DiSEqCDevRotor &m_rotor;
00318 };
00319
00321
00322 class RotorHiSpeedSetting : public LineEditSetting, public Storage
00323 {
00324 public:
00325 RotorHiSpeedSetting(DiSEqCDevRotor &rotor) :
00326 LineEditSetting(this), m_rotor(rotor)
00327 {
00328 setLabel(DeviceTree::tr("Rotor High Speed (deg/sec)"));
00329 QString help = DeviceTree::tr(
00330 "To allow the approximate monitoring of rotor movement, enter "
00331 "the rated angular speed of the rotor when powered at 18V.");
00332 setHelpText(help);
00333 }
00334
00335 virtual void load(void)
00336 {
00337 setValue(QString::number(m_rotor.GetHiSpeed()));
00338 }
00339
00340 virtual void save(void)
00341 {
00342 m_rotor.SetHiSpeed(getValue().toDouble());
00343 }
00344
00345 virtual void save(QString ) { }
00346
00347 private:
00348 DiSEqCDevRotor &m_rotor;
00349 };
00350
00352
00353 static QString AngleToString(double angle)
00354 {
00355 QString str = QString::null;
00356 if (angle >= 0.0)
00357 str = QString::number(angle) +
00358 DeviceTree::tr("E", "Eastern Hemisphere");
00359 else
00360 str = QString::number(-angle) +
00361 DeviceTree::tr("W", "Western Hemisphere");
00362 return str;
00363 }
00364
00365 static double AngleToEdit(double angle, QString &hemi)
00366 {
00367 if (angle > 0.0)
00368 {
00369 hemi = "E";
00370 return angle;
00371 }
00372
00373 hemi = "W";
00374 return -angle;
00375 }
00376
00377 static double AngleToFloat(const QString &angle, bool translated = true)
00378 {
00379 if (angle.length() < 2)
00380 return 0.0;
00381
00382 double pos;
00383 QChar postfix = angle.at(angle.length() - 1);
00384 if (postfix.isLetter())
00385 {
00386 pos = angle.left(angle.length() - 1).toDouble();
00387 if ((translated &&
00388 (postfix.upper() == DeviceTree::tr("W", "Western Hemisphere"))) ||
00389 (!translated && (postfix.upper() == "W")))
00390 {
00391 pos = -pos;
00392 }
00393 }
00394 else
00395 pos = angle.toDouble();
00396
00397 return pos;
00398 }
00399
00400 RotorPosMap::RotorPosMap(DiSEqCDevRotor &rotor) :
00401 ListBoxSetting(this), m_rotor(rotor)
00402 {
00403 connect(this, SIGNAL(editButtonPressed(int)), SLOT(edit(void)));
00404 connect(this, SIGNAL(deleteButtonPressed(int)), SLOT(del(void)));
00405 connect(this, SIGNAL(accepted(int)), SLOT(edit(void)));
00406 }
00407
00408 void RotorPosMap::load(void)
00409 {
00410 m_posmap = m_rotor.GetPosMap();
00411 PopulateList();
00412 }
00413
00414 void RotorPosMap::save(void)
00415 {
00416 m_rotor.SetPosMap(m_posmap);
00417 }
00418
00419 void RotorPosMap::edit(void)
00420 {
00421 uint id = getValue().toUInt();
00422
00423 QString angle;
00424 if (MythPopupBox::showGetTextPopup(
00425 gContext->GetMainWindow(),
00426 DeviceTree::tr("Position Index %1").arg(id),
00427 DeviceTree::tr("Orbital Position"), angle))
00428 {
00429 m_posmap[id] = AngleToFloat(angle);
00430 PopulateList();
00431 }
00432 }
00433
00434 void RotorPosMap::del(void)
00435 {
00436 uint id = getValue().toUInt();
00437 m_posmap.erase(id);
00438 PopulateList();
00439 }
00440
00441 void RotorPosMap::PopulateList(void)
00442 {
00443 int old_sel = getValueIndex(getValue());
00444 clearSelections();
00445 uint num_pos = 64;
00446 for (uint pos = 1; pos < num_pos; pos++)
00447 {
00448 uint_to_dbl_t::const_iterator it = m_posmap.find(pos);
00449 QString posval = DeviceTree::tr("None");
00450 if (it != m_posmap.end())
00451 posval = AngleToString(*it);
00452
00453 addSelection(DeviceTree::tr("Position #%1 (%2)").arg(pos).arg(posval),
00454 QString::number(pos));
00455 }
00456 setCurrentItem(old_sel);
00457 }
00458
00460
00461 class RotorPosConfig : public ConfigurationDialog
00462 {
00463 public:
00464 RotorPosConfig(DiSEqCDevRotor &rotor)
00465 {
00466 setLabel(DeviceTree::tr("Rotor Position Map"));
00467 addChild(new RotorPosMap(rotor));
00468 }
00469
00470 virtual DialogCode exec(void)
00471 {
00472 while (ConfigurationDialog::exec() == kDialogCodeAccepted);
00473 return kDialogCodeRejected;
00474 }
00475 };
00476
00478
00479 RotorConfig::RotorConfig(DiSEqCDevRotor &rotor) : m_rotor(rotor)
00480 {
00481 ConfigurationGroup *group =
00482 new VerticalConfigurationGroup(false, false);
00483 group->setLabel(DeviceTree::tr("Rotor Configuration"));
00484
00485 group->addChild(new DeviceDescrSetting(rotor));
00486 group->addChild(new DeviceRepeatSetting(rotor));
00487
00488 ConfigurationGroup *tgroup =
00489 new HorizontalConfigurationGroup(false, false, true, true);
00490
00491 RotorTypeSetting *rtype = new RotorTypeSetting(rotor);
00492 connect(rtype, SIGNAL(valueChanged(const QString&)),
00493 this, SLOT( SetType( const QString&)));
00494 tgroup->addChild(rtype);
00495
00496 m_pos = new TransButtonSetting();
00497 m_pos->setLabel(DeviceTree::tr("Positions"));
00498 m_pos->setHelpText(DeviceTree::tr("Rotor position setup."));
00499 m_pos->setEnabled(rotor.GetType() == DiSEqCDevRotor::kTypeDiSEqC_1_2);
00500 connect(m_pos, SIGNAL(pressed(void)),
00501 this, SLOT( RunRotorPositionsDialog(void)));
00502 tgroup->addChild(m_pos);
00503
00504 group->addChild(tgroup);
00505 group->addChild(new RotorLoSpeedSetting(rotor));
00506 group->addChild(new RotorHiSpeedSetting(rotor));
00507 group->addChild(DiSEqCLatitude());
00508 group->addChild(DiSEqCLongitude());
00509
00510 addChild(group);
00511 }
00512
00513 void RotorConfig::SetType(const QString &type)
00514 {
00515 DiSEqCDevRotor::dvbdev_rotor_t rtype;
00516 rtype = (DiSEqCDevRotor::dvbdev_rotor_t) type.toUInt();
00517 m_pos->setEnabled(rtype == DiSEqCDevRotor::kTypeDiSEqC_1_2);
00518 }
00519
00520 void RotorConfig::RunRotorPositionsDialog(void)
00521 {
00522 RotorPosConfig config(m_rotor);
00523 config.exec();
00524 config.save();
00525 }
00526
00528
00529 class lnb_preset
00530 {
00531 public:
00532 lnb_preset(const QString &_name, DiSEqCDevLNB::dvbdev_lnb_t _type,
00533 uint _lof_sw = 0, uint _lof_lo = 0,
00534 uint _lof_hi = 0, bool _pol_inv = false) :
00535 name(_name), type(_type),
00536 lof_sw(_lof_sw), lof_lo(_lof_lo),
00537 lof_hi(_lof_hi), pol_inv(_pol_inv) {}
00538
00539 public:
00540 QString name;
00541 DiSEqCDevLNB::dvbdev_lnb_t type;
00542 uint lof_sw;
00543 uint lof_lo;
00544 uint lof_hi;
00545 bool pol_inv;
00546 };
00547
00548 static lnb_preset lnb_presets[] =
00549 {
00550
00551 lnb_preset(DeviceTree::tr("Single (Europe)"),
00552 DiSEqCDevLNB::kTypeVoltageControl, 0, 9750000),
00553 lnb_preset(DeviceTree::tr("Universal (Europe)"),
00554 DiSEqCDevLNB::kTypeVoltageAndToneControl,
00555 11700000, 9750000, 10600000),
00556 lnb_preset(DeviceTree::tr("Circular (N. America)"),
00557 DiSEqCDevLNB::kTypeVoltageControl, 0, 11250000),
00558 lnb_preset(DeviceTree::tr("Linear (N. America)"),
00559 DiSEqCDevLNB::kTypeVoltageControl, 0, 10750000),
00560 lnb_preset(DeviceTree::tr("C Band"),
00561 DiSEqCDevLNB::kTypeVoltageControl, 0, 5150000),
00562 lnb_preset(DeviceTree::tr("DishPro Bandstacked"),
00563 DiSEqCDevLNB::kTypeBandstacked, 0, 11250000, 14350000),
00564 lnb_preset(QString::null, DiSEqCDevLNB::kTypeVoltageControl),
00565 };
00566
00567 uint FindPreset(const DiSEqCDevLNB &lnb)
00568 {
00569 uint i;
00570 for (i = 0; !lnb_presets[i].name.isEmpty(); i++)
00571 {
00572 if (lnb_presets[i].type == lnb.GetType() &&
00573 lnb_presets[i].lof_sw == lnb.GetLOFSwitch() &&
00574 lnb_presets[i].lof_lo == lnb.GetLOFLow() &&
00575 lnb_presets[i].lof_hi == lnb.GetLOFHigh() &&
00576 lnb_presets[i].pol_inv== lnb.IsPolarityInverted())
00577 {
00578 break;
00579 }
00580 }
00581 return i;
00582 }
00583
00584 class LNBPresetSetting : public ComboBoxSetting, public Storage
00585 {
00586 public:
00587 LNBPresetSetting(DiSEqCDevLNB &lnb) : ComboBoxSetting(this), m_lnb(lnb)
00588 {
00589 setLabel(DeviceTree::tr("LNB Preset"));
00590 QString help = DeviceTree::tr(
00591 "Select the LNB preset from the list, or choose "
00592 "'Custom' and set the advanced settings below.");
00593 setHelpText(help);
00594
00595 uint i = 0;
00596 for (; !lnb_presets[i].name.isEmpty(); i++)
00597 addSelection(lnb_presets[i].name, QString::number(i));
00598 addSelection(DeviceTree::tr("Custom"), QString::number(i));
00599 }
00600
00601 virtual void load(void)
00602 {
00603 setValue(FindPreset(m_lnb));
00604 }
00605
00606 virtual void save(void)
00607 {
00608 }
00609
00610 virtual void save(QString )
00611 {
00612 }
00613
00614 private:
00615 DiSEqCDevLNB &m_lnb;
00616 };
00617
00619
00620 class LNBTypeSetting : public ComboBoxSetting, public Storage
00621 {
00622 public:
00623 LNBTypeSetting(DiSEqCDevLNB &lnb) : ComboBoxSetting(this), m_lnb(lnb)
00624 {
00625 setLabel(DeviceTree::tr("LNB Type"));
00626 setHelpText(DeviceTree::tr("Select the type of LNB from the list."));
00627 addSelection(DeviceTree::tr("Legacy (Fixed)"),
00628 QString::number((uint) DiSEqCDevLNB::kTypeFixed));
00629 addSelection(DeviceTree::tr("Standard (Voltage)"),
00630 QString::number((uint) DiSEqCDevLNB::
00631 kTypeVoltageControl));
00632 addSelection(DeviceTree::tr("Universal (Voltage & Tone)"),
00633 QString::number((uint) DiSEqCDevLNB::
00634 kTypeVoltageAndToneControl));
00635 addSelection(DeviceTree::tr("Bandstacked"),
00636 QString::number((uint) DiSEqCDevLNB::kTypeBandstacked));
00637 }
00638
00639 virtual void load(void)
00640 {
00641 setValue(getValueIndex(QString::number((uint) m_lnb.GetType())));
00642 }
00643
00644 virtual void save(void)
00645 {
00646 m_lnb.SetType((DiSEqCDevLNB::dvbdev_lnb_t) getValue().toUInt());
00647 }
00648
00649 virtual void save(QString ) { }
00650
00651 private:
00652 DiSEqCDevLNB &m_lnb;
00653 };
00654
00656
00657 class LNBLOFSwitchSetting : public LineEditSetting, public Storage
00658 {
00659 public:
00660 LNBLOFSwitchSetting(DiSEqCDevLNB &lnb) : LineEditSetting(this), m_lnb(lnb)
00661 {
00662 setLabel(DeviceTree::tr("LNB LOF Switch (MHz)"));
00663 QString help = DeviceTree::tr(
00664 "This defines at what frequency the LNB will do a "
00665 "switch from high to low setting, and vice versa.");
00666 setHelpText(help);
00667 }
00668
00669 virtual void load(void)
00670 {
00671 setValue(QString::number(m_lnb.GetLOFSwitch() / 1000));
00672 }
00673
00674 virtual void save(void)
00675 {
00676 m_lnb.SetLOFSwitch(getValue().toUInt() * 1000);
00677 }
00678
00679 virtual void save(QString ) { }
00680
00681 private:
00682 DiSEqCDevLNB &m_lnb;
00683 };
00684
00686
00687 class LNBLOFLowSetting : public LineEditSetting, public Storage
00688 {
00689 public:
00690 LNBLOFLowSetting(DiSEqCDevLNB &lnb) : LineEditSetting(this), m_lnb(lnb)
00691 {
00692 setLabel(DeviceTree::tr("LNB LOF Low (MHz)"));
00693 QString help = DeviceTree::tr(
00694 "This defines the offset the frequency coming "
00695 "from the LNB will be in low setting. For bandstacked "
00696 "LNBs this is the vertical/right polarization band.");
00697 setHelpText(help);
00698 }
00699
00700 virtual void load(void)
00701 {
00702 setValue(QString::number(m_lnb.GetLOFLow() / 1000));
00703 }
00704
00705 virtual void save(void)
00706 {
00707 m_lnb.SetLOFLow(getValue().toUInt() * 1000);
00708 }
00709
00710 virtual void save(QString ) { }
00711
00712 private:
00713 DiSEqCDevLNB &m_lnb;
00714 };
00715
00717
00718 class LNBLOFHighSetting : public LineEditSetting, public Storage
00719 {
00720 public:
00721 LNBLOFHighSetting(DiSEqCDevLNB &lnb) : LineEditSetting(this), m_lnb(lnb)
00722 {
00723 setLabel(DeviceTree::tr("LNB LOF High (MHz)"));
00724 QString help = DeviceTree::tr(
00725 "This defines the offset the frequency coming from "
00726 "the LNB will be in high setting. For bandstacked "
00727 "LNBs this is the horizontal/left polarization band.");
00728 setHelpText(help);
00729 }
00730
00731 virtual void load(void)
00732 {
00733 setValue(QString::number(m_lnb.GetLOFHigh() / 1000));
00734 }
00735
00736 virtual void save(void)
00737 {
00738 m_lnb.SetLOFHigh(getValue().toUInt() * 1000);
00739 }
00740
00741 virtual void save(QString ) { }
00742
00743 private:
00744 DiSEqCDevLNB &m_lnb;
00745 };
00746
00747 class LNBPolarityInvertedSetting : public CheckBoxSetting, public Storage
00748 {
00749 public:
00750 LNBPolarityInvertedSetting(DiSEqCDevLNB &lnb) :
00751 CheckBoxSetting(this), m_lnb(lnb)
00752 {
00753 setLabel(DeviceTree::tr("LNB Reversed"));
00754 QString help = DeviceTree::tr(
00755 "This defines whether the signal reaching the LNB "
00756 "is reversed from normal polarization. This happens "
00757 "to circular signals bouncing twice on a toroidal "
00758 "dish.");
00759 setHelpText(help);
00760 }
00761
00762 virtual void load(void)
00763 {
00764 setValue(m_lnb.IsPolarityInverted());
00765 }
00766
00767 virtual void save(void)
00768 {
00769 m_lnb.SetPolarityInverted(boolValue());
00770 }
00771
00772 virtual void save(QString ) { }
00773
00774 private:
00775 DiSEqCDevLNB &m_lnb;
00776 };
00777
00779
00780 LNBConfig::LNBConfig(DiSEqCDevLNB &lnb)
00781 {
00782 ConfigurationGroup *group =
00783 new VerticalConfigurationGroup(false, false);
00784 group->setLabel(DeviceTree::tr("LNB Configuration"));
00785
00786 group->addChild(new DeviceDescrSetting(lnb));
00787 LNBPresetSetting *preset = new LNBPresetSetting(lnb);
00788 group->addChild(preset);
00789 m_type = new LNBTypeSetting(lnb);
00790 group->addChild(m_type);
00791 m_lof_switch = new LNBLOFSwitchSetting(lnb);
00792 group->addChild(m_lof_switch);
00793 m_lof_lo = new LNBLOFLowSetting(lnb);
00794 group->addChild(m_lof_lo);
00795 m_lof_hi = new LNBLOFHighSetting(lnb);
00796 group->addChild(m_lof_hi);
00797 m_pol_inv = new LNBPolarityInvertedSetting(lnb);
00798 group->addChild(m_pol_inv);
00799 connect(m_type, SIGNAL(valueChanged(const QString&)),
00800 this, SLOT( UpdateType( void)));
00801 connect(preset, SIGNAL(valueChanged(const QString&)),
00802 this, SLOT( SetPreset( const QString&)));
00803 addChild(group);
00804 }
00805
00806 void LNBConfig::SetPreset(const QString &value)
00807 {
00808 uint index = value.toUInt();
00809 if (index >= (sizeof(lnb_presets) / sizeof(lnb_preset)))
00810 return;
00811
00812 lnb_preset &preset = lnb_presets[index];
00813 if (preset.name == NULL)
00814 {
00815 m_type->setEnabled(true);
00816 UpdateType();
00817 }
00818 else
00819 {
00820 m_type->setValue(m_type->getValueIndex(
00821 QString::number((uint)preset.type)));
00822 m_lof_switch->setValue(QString::number(preset.lof_sw / 1000));
00823 m_lof_lo->setValue(QString::number(preset.lof_lo / 1000));
00824 m_lof_hi->setValue(QString::number(preset.lof_hi / 1000));
00825 m_pol_inv->setValue(preset.pol_inv);
00826 m_type->setEnabled(false);
00827 m_lof_switch->setEnabled(false);
00828 m_lof_hi->setEnabled(false);
00829 m_lof_lo->setEnabled(false);
00830 m_pol_inv->setEnabled(false);
00831 }
00832 }
00833
00834 void LNBConfig::UpdateType(void)
00835 {
00836 if (!m_type->isEnabled())
00837 return;
00838
00839 switch ((DiSEqCDevLNB::dvbdev_lnb_t) m_type->getValue().toUInt())
00840 {
00841 case DiSEqCDevLNB::kTypeFixed:
00842 case DiSEqCDevLNB::kTypeVoltageControl:
00843 m_lof_switch->setEnabled(false);
00844 m_lof_hi->setEnabled(false);
00845 m_lof_lo->setEnabled(true);
00846 m_pol_inv->setEnabled(true);
00847 break;
00848 case DiSEqCDevLNB::kTypeVoltageAndToneControl:
00849 m_lof_switch->setEnabled(true);
00850 m_lof_hi->setEnabled(true);
00851 m_lof_lo->setEnabled(true);
00852 m_pol_inv->setEnabled(true);
00853 break;
00854 case DiSEqCDevLNB::kTypeBandstacked:
00855 m_lof_switch->setEnabled(false);
00856 m_lof_hi->setEnabled(true);
00857 m_lof_lo->setEnabled(true);
00858 m_pol_inv->setEnabled(true);
00859 break;
00860 }
00861 }
00862
00864
00865 DeviceTree::DeviceTree(DiSEqCDevTree &tree) :
00866 ListBoxSetting(this), m_tree(tree)
00867 {
00868 connect(this, SIGNAL(editButtonPressed(int)), SLOT(edit(void)));
00869 connect(this, SIGNAL(deleteButtonPressed(int)), SLOT(del(void)));
00870 connect(this, SIGNAL(accepted(int)), SLOT(edit(void)));
00871 }
00872
00873 void DeviceTree::load(void)
00874 {
00875 PopulateTree();
00876 }
00877
00878 void DeviceTree::save(void)
00879 {
00880 }
00881
00882 bool DeviceTree::EditNodeDialog(uint nodeid)
00883 {
00884 DiSEqCDevDevice *dev = m_tree.FindDevice(nodeid);
00885 if (!dev)
00886 {
00887 VERBOSE(VB_IMPORTANT, QString("DeviceTree::EditNodeDialog(%1) "
00888 "-- device not found").arg(nodeid));
00889 return false;
00890 }
00891
00892 bool changed = false;
00893 switch (dev->GetDeviceType())
00894 {
00895 case DiSEqCDevDevice::kTypeSwitch:
00896 {
00897 DiSEqCDevSwitch *sw = dynamic_cast<DiSEqCDevSwitch*>(dev);
00898 if (sw)
00899 {
00900 SwitchConfig config(*sw);
00901 changed = (config.exec() == MythDialog::Accepted);
00902 }
00903 }
00904 break;
00905
00906 case DiSEqCDevDevice::kTypeRotor:
00907 {
00908 DiSEqCDevRotor *rotor = dynamic_cast<DiSEqCDevRotor*>(dev);
00909 if (rotor)
00910 {
00911 RotorConfig config(*rotor);
00912 changed = (config.exec() == MythDialog::Accepted);
00913 }
00914 }
00915 break;
00916
00917 case DiSEqCDevDevice::kTypeLNB:
00918 {
00919 DiSEqCDevLNB *lnb = dynamic_cast<DiSEqCDevLNB*>(dev);
00920 if (lnb)
00921 {
00922 LNBConfig config(*lnb);
00923 changed = (config.exec() == MythDialog::Accepted);
00924 }
00925 }
00926 break;
00927
00928 default:
00929 break;
00930 }
00931
00932 if (changed)
00933 PopulateTree();
00934
00935 return changed;
00936 }
00937
00938 bool DeviceTree::RunTypeDialog(DiSEqCDevDevice::dvbdev_t &type)
00939 {
00940 MythPopupBox *popup = new MythPopupBox(gContext->GetMainWindow(), "");
00941 popup->addLabel(tr("Select Type of Device"));
00942
00943 MythListBox *list = new MythListBox(popup);
00944 list->setScrollBar(false);
00945 list->setBottomScrollBar(false);
00946 list->insertItem(tr("Switch"));
00947 list->insertItem(tr("Rotor"));
00948 list->insertItem(tr("LNB"));
00949 list->setCurrentItem(0);
00950
00951 popup->addWidget(list);
00952 connect(list, SIGNAL(accepted(int)),
00953 popup, SLOT( AcceptItem(int)));
00954 list->setFocus();
00955
00956 DialogCode res = popup->ExecPopup();
00957 type = (DiSEqCDevDevice::dvbdev_t)list->currentItem();
00958
00959 popup->hide();
00960 popup->deleteLater();
00961
00962 return kDialogCodeRejected != res;
00963 }
00964
00965 void DeviceTree::CreateRootNodeDialog(void)
00966 {
00967 DiSEqCDevDevice::dvbdev_t type;
00968 if (!RunTypeDialog(type))
00969 return;
00970
00971 DiSEqCDevDevice *dev = DiSEqCDevDevice::CreateByType(m_tree, type);
00972 if (dev)
00973 {
00974 m_tree.SetRoot(dev);
00975
00976 if (!EditNodeDialog(dev->GetDeviceID()))
00977 m_tree.SetRoot(NULL);
00978
00979 PopulateTree();
00980 }
00981 }
00982
00983 void DeviceTree::CreateNewNodeDialog(uint parentid, uint child_num)
00984 {
00985 DiSEqCDevDevice *parent = m_tree.FindDevice(parentid);
00986 if (!parent)
00987 return;
00988
00989 DiSEqCDevDevice::dvbdev_t type;
00990 if (RunTypeDialog(type))
00991 {
00992 DiSEqCDevDevice *dev = DiSEqCDevDevice::CreateByType(m_tree, type);
00993 if (!dev)
00994 return;
00995
00996 if (parent->SetChild(child_num, dev))
00997 {
00998 if (!EditNodeDialog(dev->GetDeviceID()))
00999 parent->SetChild(child_num, NULL);
01000 PopulateTree();
01001 }
01002 else
01003 {
01004 delete dev;
01005 }
01006 }
01007 }
01008
01009 void DeviceTree::edit(void)
01010 {
01011 QString id = getValue();
01012 if (id.find(':') == -1)
01013 {
01014 EditNodeDialog(id.toUInt());
01015 }
01016 else
01017 {
01018 QStringList vals = QStringList::split(':', id, true);
01019 if (vals[0].isEmpty())
01020 CreateRootNodeDialog();
01021 else
01022 CreateNewNodeDialog(vals[0].toUInt(), vals[1].toUInt());
01023 }
01024 setFocus();
01025 }
01026
01027 void DeviceTree::del(void)
01028 {
01029 QString id = getValue();
01030
01031 if (id.find(':') == -1)
01032 {
01033 uint nodeid = id.toUInt();
01034 DiSEqCDevDevice *dev = m_tree.FindDevice(nodeid);
01035 if (dev)
01036 {
01037 DiSEqCDevDevice *parent = dev->GetParent();
01038 if (parent)
01039 parent->SetChild(dev->GetOrdinal(), NULL);
01040 else
01041 m_tree.SetRoot(NULL);
01042
01043 PopulateTree();
01044 }
01045 }
01046
01047 setFocus();
01048 }
01049
01050 void DeviceTree::PopulateTree(void)
01051 {
01052 int old_sel = getValueIndex(getValue());
01053 clearSelections();
01054 PopulateTree(m_tree.Root());
01055 setCurrentItem(old_sel);
01056 }
01057
01058 void DeviceTree::PopulateTree(DiSEqCDevDevice *node,
01059 DiSEqCDevDevice *parent,
01060 uint childnum,
01061 uint depth)
01062 {
01063 QString indent;
01064 indent.fill(' ', 8 * depth);
01065
01066 if (node)
01067 {
01068 QString id = QString::number(node->GetDeviceID());
01069 addSelection(indent + node->GetDescription(), id);
01070 uint num_ch = node->GetChildCount();
01071 for (uint ch = 0; ch < num_ch; ch++)
01072 PopulateTree(node->GetChild(ch), node, ch, depth+1);
01073 }
01074 else
01075 {
01076 QString id;
01077 if (parent)
01078 id = QString::number(parent->GetDeviceID());
01079 id += ":" + QString::number(childnum);
01080
01081 addSelection(indent + "(Unconnected)", id);
01082 }
01083 }
01084
01086
01087 DTVDeviceTreeWizard::DTVDeviceTreeWizard(DiSEqCDevTree &tree)
01088 {
01089 setLabel(DeviceTree::tr("DiSEqC Device Tree"));
01090 addChild(new DeviceTree(tree));
01091 }
01092
01093 DialogCode DTVDeviceTreeWizard::exec(void)
01094 {
01095 while (ConfigurationDialog::exec() == kDialogCodeAccepted);
01096 return kDialogCodeRejected;
01097 }
01098
01100
01101 class SwitchSetting : public ComboBoxSetting, public Storage
01102 {
01103 public:
01104 SwitchSetting(DiSEqCDevDevice &node, DiSEqCDevSettings &settings)
01105 : ComboBoxSetting(this), m_node(node), m_settings(settings)
01106 {
01107 setLabel(node.GetDescription());
01108 setHelpText(DeviceTree::tr("Choose a port to use for this switch."));
01109
01110 uint num_children = node.GetChildCount();
01111 for (uint ch = 0; ch < num_children; ch++)
01112 {
01113 QString val = QString("%1").arg(ch);
01114 QString descr = DeviceTree::tr("Port %1").arg(ch+1);
01115 DiSEqCDevDevice *child = node.GetChild(ch);
01116 if (child)
01117 descr += QString(" (%2)").arg(child->GetDescription());
01118 addSelection(descr, val);
01119 }
01120 }
01121
01122 virtual void load(void)
01123 {
01124 double value = m_settings.GetValue(m_node.GetDeviceID());
01125 setValue((uint)value);
01126 }
01127
01128 virtual void save(void)
01129 {
01130 m_settings.SetValue(m_node.GetDeviceID(), getValue().toDouble());
01131 }
01132
01133 virtual void save(QString ) {}
01134
01135 private:
01136 DiSEqCDevDevice &m_node;
01137 DiSEqCDevSettings &m_settings;
01138 };
01139
01141
01142 class RotorSetting : public ComboBoxSetting, public Storage
01143 {
01144 public:
01145 RotorSetting(DiSEqCDevDevice &node, DiSEqCDevSettings &settings)
01146 : ComboBoxSetting(this), m_node(node), m_settings(settings)
01147 {
01148 setLabel(node.GetDescription());
01149 setHelpText(DeviceTree::tr("Choose a satellite position."));
01150
01151 DiSEqCDevRotor *rotor = dynamic_cast<DiSEqCDevRotor*>(&m_node);
01152 if (rotor)
01153 m_posmap = rotor->GetPosMap();
01154 }
01155
01156 virtual void load(void)
01157 {
01158 clearSelections();
01159
01160 uint_to_dbl_t::const_iterator it;
01161 for (it = m_posmap.begin(); it != m_posmap.end(); ++it)
01162 addSelection(AngleToString(*it), QString::number(*it));
01163
01164 double angle = m_settings.GetValue(m_node.GetDeviceID());
01165 setValue(getValueIndex(QString::number(angle)));
01166 }
01167
01168 virtual void save(void)
01169 {
01170 m_settings.SetValue(m_node.GetDeviceID(), getValue().toDouble());
01171 }
01172
01173 virtual void save(QString ) { }
01174
01175 private:
01176 DiSEqCDevDevice &m_node;
01177 DiSEqCDevSettings &m_settings;
01178 uint_to_dbl_t m_posmap;
01179 };
01180
01182
01183 class USALSRotorSetting : public HorizontalConfigurationGroup
01184 {
01185 public:
01186 USALSRotorSetting(DiSEqCDevDevice &node, DiSEqCDevSettings &settings) :
01187 HorizontalConfigurationGroup(false, false, true, true),
01188 numeric(new TransLineEditSetting()),
01189 hemisphere(new TransComboBoxSetting(false)),
01190 m_node(node), m_settings(settings)
01191 {
01192 QString help =
01193 DeviceTree::tr(
01194 "Locates the satellite you wish to point to "
01195 "with the longitude along the Clarke Belt of "
01196 "the satellite [-180..180] and its hemisphere.");
01197
01198 numeric->setLabel(DeviceTree::tr("Longitude (degrees)"));
01199 numeric->setHelpText(help);
01200 hemisphere->setLabel(DeviceTree::tr("Hemisphere"));
01201 hemisphere->addSelection(DeviceTree::tr("Eastern"), "E", false);
01202 hemisphere->addSelection(DeviceTree::tr("Western"), "W", true);
01203 hemisphere->setHelpText(help);
01204
01205 addChild(numeric);
01206 addChild(hemisphere);
01207 }
01208
01209 virtual void load(void)
01210 {
01211 double val = m_settings.GetValue(m_node.GetDeviceID());
01212 QString hemi = QString::null;
01213 double eval = AngleToEdit(val, hemi);
01214 numeric->setValue(QString::number(eval));
01215 hemisphere->setValue(hemisphere->getValueIndex(hemi));
01216 }
01217
01218 virtual void save(void)
01219 {
01220 QString val = QString::number(numeric->getValue().toDouble());
01221 val += hemisphere->getValue();
01222 m_settings.SetValue(m_node.GetDeviceID(), AngleToFloat(val, false));
01223 }
01224
01225 virtual void save(QString ) { }
01226
01227 private:
01228 TransLineEditSetting *numeric;
01229 TransComboBoxSetting *hemisphere;
01230 DiSEqCDevDevice &m_node;
01231 DiSEqCDevSettings &m_settings;
01232 };
01233
01235
01236 DTVDeviceConfigGroup::DTVDeviceConfigGroup(
01237 DiSEqCDevSettings &settings, uint cardid, bool switches_enabled) :
01238 VerticalConfigurationGroup(false, false, true, true),
01239 m_settings(settings), m_switches_enabled(switches_enabled)
01240 {
01241 setLabel(DeviceTree::tr("DTV Device Configuration"));
01242
01243
01244 m_tree.Load(cardid);
01245
01246
01247 AddNodes(this, QString::null, m_tree.Root());
01248 }
01249
01250 DTVDeviceConfigGroup::~DTVDeviceConfigGroup(void)
01251 {
01252 }
01253
01254 void DTVDeviceConfigGroup::AddNodes(
01255 ConfigurationGroup *group, const QString &trigger, DiSEqCDevDevice *node)
01256 {
01257 if (!node)
01258 return;
01259
01260 Setting *setting = NULL;
01261 switch (node->GetDeviceType())
01262 {
01263 case DiSEqCDevDevice::kTypeSwitch:
01264 setting = new SwitchSetting(*node, m_settings);
01265 setting->setEnabled(m_switches_enabled);
01266 break;
01267 case DiSEqCDevDevice::kTypeRotor:
01268 {
01269 DiSEqCDevRotor *rotor = dynamic_cast<DiSEqCDevRotor*>(node);
01270 if (rotor && (rotor->GetType() == DiSEqCDevRotor::kTypeDiSEqC_1_2))
01271 setting = new RotorSetting(*node, m_settings);
01272 else
01273 setting = new USALSRotorSetting(*node, m_settings);
01274 break;
01275 }
01276 default:
01277 break;
01278 }
01279
01280 if (!setting)
01281 {
01282 AddChild(group, trigger, new TransLabelSetting());
01283 return;
01284 }
01285
01286 m_devs[node->GetDeviceID()] = setting;
01287
01288 uint num_ch = node->GetChildCount();
01289 if (DiSEqCDevDevice::kTypeSwitch == node->GetDeviceType())
01290 {
01291 bool useframe = (node != m_tree.Root());
01292 bool zerospace = !useframe;
01293 TriggeredConfigurationGroup *cgrp = new TriggeredConfigurationGroup(
01294 false, useframe, true, true, false, false, true, zerospace);
01295
01296 cgrp->addChild(setting);
01297 cgrp->setTrigger(setting);
01298
01299 for (uint i = 0; i < num_ch; i++)
01300 AddNodes(cgrp, QString::number(i), node->GetChild(i));
01301
01302 AddChild(group, trigger, cgrp);
01303 return;
01304 }
01305
01306 if (!num_ch)
01307 {
01308 AddChild(group, trigger, setting);
01309 return;
01310 }
01311
01312 VerticalConfigurationGroup *cgrp =
01313 new VerticalConfigurationGroup(false, false, true, true);
01314
01315 AddChild(cgrp, QString::null, setting);
01316 for (uint i = 0; i < num_ch; i++)
01317 AddNodes(cgrp, QString::null, node->GetChild(i));
01318
01319 AddChild(group, trigger, cgrp);
01320 }
01321
01322 void DTVDeviceConfigGroup::AddChild(
01323 ConfigurationGroup *group, const QString &trigger, Setting *setting)
01324 {
01325 TriggeredConfigurationGroup *grp =
01326 dynamic_cast<TriggeredConfigurationGroup*>(group);
01327
01328 if (grp && !trigger.isEmpty())
01329 grp->addTarget(trigger, setting);
01330 else
01331 group->addChild(setting);
01332 }
01333
01335
01336 enum OLD_DISEQC_TYPES
01337 {
01338 DISEQC_SINGLE = 0,
01339 DISEQC_MINI_2 = 1,
01340 DISEQC_SWITCH_2_1_0 = 2,
01341 DISEQC_SWITCH_2_1_1 = 3,
01342 DISEQC_SWITCH_4_1_0 = 4,
01343 DISEQC_SWITCH_4_1_1 = 5,
01344 DISEQC_POSITIONER_1_2 = 6,
01345 DISEQC_POSITIONER_X = 7,
01346 DISEQC_POSITIONER_1_2_SWITCH_2 = 8,
01347 DISEQC_POSITIONER_X_SWITCH_2 = 9,
01348 DISEQC_SW21 = 10,
01349 DISEQC_SW64 = 11,
01350 };
01351
01352
01353 bool convert_diseqc_db(void)
01354 {
01355 MSqlQuery cquery(MSqlQuery::InitCon());
01356 cquery.prepare(
01357 "SELECT cardid, dvb_diseqc_type "
01358 "FROM capturecard"
01359 "WHERE dvb_diseqc_type IS NOT NULL AND "
01360 " diseqcid IS NULL");
01361
01362
01363 if (!cquery.exec())
01364 return false;
01365
01366 MSqlQuery iquery(MSqlQuery::InitCon());
01367 iquery.prepare(
01368 "SELECT cardinputid, diseqc_port, diseqc_pos, "
01369 " lnb_lof_switch, lnb_lof_hi, lnb_lof_lo "
01370 "FROM cardinput "
01371 "WHERE cardinput.cardid = :CARDID");
01372
01373 while (cquery.next())
01374 {
01375 uint cardid = cquery.value(0).toUInt();
01376 OLD_DISEQC_TYPES type = (OLD_DISEQC_TYPES) cquery.value(1).toUInt();
01377
01378 DiSEqCDevTree tree;
01379 DiSEqCDevDevice *root = NULL;
01380 uint add_lnbs = 0;
01381 DiSEqCDevLNB::dvbdev_lnb_t lnb_type =
01382 DiSEqCDevLNB::kTypeVoltageAndToneControl;
01383
01384
01385 switch (type)
01386 {
01387 case DISEQC_SINGLE:
01388 {
01389
01390 root = DiSEqCDevDevice::CreateByType(
01391 tree, DiSEqCDevDevice::kTypeLNB);
01392 break;
01393 }
01394
01395 case DISEQC_MINI_2:
01396 {
01397
01398 root = DiSEqCDevDevice::CreateByType(
01399 tree, DiSEqCDevDevice::kTypeSwitch);
01400 DiSEqCDevSwitch *sw = dynamic_cast<DiSEqCDevSwitch*>(root);
01401 sw->SetType(DiSEqCDevSwitch::kTypeTone);
01402 sw->SetNumPorts(2);
01403 add_lnbs = 2;
01404 break;
01405 }
01406
01407 case DISEQC_SWITCH_2_1_0:
01408 case DISEQC_SWITCH_2_1_1:
01409 {
01410
01411 root = DiSEqCDevDevice::CreateByType(
01412 tree, DiSEqCDevDevice::kTypeSwitch);
01413 DiSEqCDevSwitch *sw = dynamic_cast<DiSEqCDevSwitch*>(root);
01414 sw->SetType(DiSEqCDevSwitch::kTypeDiSEqCCommitted);
01415 sw->SetNumPorts(2);
01416 add_lnbs = 2;
01417 break;
01418 }
01419
01420 case DISEQC_SWITCH_4_1_0:
01421 case DISEQC_SWITCH_4_1_1:
01422 {
01423
01424 root = DiSEqCDevDevice::CreateByType(
01425 tree, DiSEqCDevDevice::kTypeSwitch);
01426 DiSEqCDevSwitch *sw = dynamic_cast<DiSEqCDevSwitch*>(root);
01427 sw->SetType(DiSEqCDevSwitch::kTypeDiSEqCCommitted);
01428 sw->SetNumPorts(4);
01429 add_lnbs = 4;
01430 break;
01431 }
01432
01433 case DISEQC_POSITIONER_1_2:
01434 {
01435
01436 root = DiSEqCDevDevice::CreateByType(
01437 tree, DiSEqCDevDevice::kTypeRotor);
01438 DiSEqCDevRotor *rotor = dynamic_cast<DiSEqCDevRotor*>(root);
01439 rotor->SetType(DiSEqCDevRotor::kTypeDiSEqC_1_2);
01440 add_lnbs = 1;
01441 break;
01442 }
01443
01444 case DISEQC_POSITIONER_X:
01445 {
01446
01447 root = DiSEqCDevDevice::CreateByType(
01448 tree, DiSEqCDevDevice::kTypeRotor);
01449 DiSEqCDevRotor *rotor = dynamic_cast<DiSEqCDevRotor*>(root);
01450 rotor->SetType(DiSEqCDevRotor::kTypeDiSEqC_1_3);
01451 add_lnbs = 1;
01452 break;
01453 }
01454
01455 case DISEQC_POSITIONER_1_2_SWITCH_2:
01456 {
01457
01458 root = DiSEqCDevDevice::CreateByType(
01459 tree, DiSEqCDevDevice::kTypeSwitch);
01460 DiSEqCDevSwitch *sw = dynamic_cast<DiSEqCDevSwitch*>(root);
01461 sw->SetType(DiSEqCDevSwitch::kTypeDiSEqCUncommitted);
01462 sw->SetNumPorts(10);
01463 add_lnbs = 10;
01464 break;
01465 }
01466
01467 case DISEQC_SW21:
01468 {
01469
01470 root = DiSEqCDevDevice::CreateByType(
01471 tree, DiSEqCDevDevice::kTypeSwitch);
01472 DiSEqCDevSwitch *sw = dynamic_cast<DiSEqCDevSwitch*>(root);
01473 sw->SetType(DiSEqCDevSwitch::kTypeLegacySW21);
01474 sw->SetNumPorts(2);
01475 add_lnbs = 2;
01476 lnb_type = DiSEqCDevLNB::kTypeFixed;
01477 break;
01478 }
01479
01480 case DISEQC_SW64:
01481 {
01482
01483 root = DiSEqCDevDevice::CreateByType(
01484 tree, DiSEqCDevDevice::kTypeSwitch);
01485 DiSEqCDevSwitch *sw = dynamic_cast<DiSEqCDevSwitch*>(root);
01486 sw->SetType(DiSEqCDevSwitch::kTypeLegacySW64);
01487 sw->SetNumPorts(3);
01488 add_lnbs = 3;
01489 lnb_type = DiSEqCDevLNB::kTypeFixed;
01490 break;
01491 }
01492
01493 default:
01494 {
01495 VERBOSE(VB_IMPORTANT, QString("Unknown DiSEqC device type ") +
01496 QString("%1 ignoring card %2").arg(type).arg(cardid));
01497 break;
01498 }
01499 }
01500
01501 if (!root)
01502 continue;
01503
01504 tree.SetRoot(root);
01505
01506
01507 for (uint i = 0; i < add_lnbs; i++)
01508 {
01509 DiSEqCDevLNB *lnb = dynamic_cast<DiSEqCDevLNB*>
01510 (DiSEqCDevDevice::CreateByType(
01511 tree, DiSEqCDevDevice::kTypeLNB));
01512 lnb->SetType(lnb_type);
01513 lnb->SetDescription(QString("LNB #%1").arg(i+1));
01514 if (!root->SetChild(i, lnb))
01515 delete lnb;
01516 }
01517
01518
01519 tree.Store(cardid);
01520
01521
01522 DiSEqCDevSettings set;
01523 iquery.bindValue(":CARDID", cardid);
01524
01525 if (!iquery.exec())
01526 return false;
01527
01528 while (iquery.next())
01529 {
01530 uint inputid = iquery.value(0).toUInt();
01531 uint port = iquery.value(1).toUInt();
01532 double pos = iquery.value(2).toDouble();
01533 DiSEqCDevLNB *lnb = NULL;
01534
01535
01536 switch (type)
01537 {
01538 case DISEQC_SINGLE:
01539 lnb = dynamic_cast<DiSEqCDevLNB*>(root);
01540 break;
01541
01542 case DISEQC_MINI_2:
01543 case DISEQC_SWITCH_2_1_0:
01544 case DISEQC_SWITCH_2_1_1:
01545 case DISEQC_SWITCH_4_1_0:
01546 case DISEQC_SWITCH_4_1_1:
01547 case DISEQC_SW21:
01548 case DISEQC_SW64:
01549 case DISEQC_POSITIONER_1_2_SWITCH_2:
01550 lnb = dynamic_cast<DiSEqCDevLNB*>(root->GetChild(port));
01551 set.SetValue(root->GetDeviceID(), port);
01552 break;
01553
01554 case DISEQC_POSITIONER_1_2:
01555 case DISEQC_POSITIONER_X:
01556 lnb = dynamic_cast<DiSEqCDevLNB*>(root->GetChild(0));
01557 set.SetValue(root->GetDeviceID(), pos);
01558 break;
01559
01560 default:
01561 break;
01562 }
01563
01564
01565 if (lnb)
01566 {
01567 lnb->SetLOFSwitch(iquery.value(3).toUInt());
01568 lnb->SetLOFHigh(iquery.value(4).toUInt());
01569 lnb->SetLOFLow(iquery.value(5).toUInt());
01570 }
01571
01572
01573 set.Store(inputid);
01574 }
01575
01576
01577 tree.Store(cardid);
01578
01579
01580 DiSEqCDev trees;
01581 trees.InvalidateTrees();
01582 }
01583
01584 return true;
01585 }